1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Check boxes example?

Discussion in 'XenForo Development Discussions' started by MatthewH, May 16, 2015.

  1. MatthewH

    MatthewH Member

    I've been searching for one, I'm trying to work with check boxes in the options however I'm not finding much information on usage for it.

    Anyone have an example for it?
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    Look at an existing admin option/template to see how they're used.
     
  3. MatthewH

    MatthewH Member

    @Brogan you're like my XenForo parent. You always seem to be the one to help me! :whistle:(y):love:

    Okay, so I'm seeing this.
    Code:
    a:4:{s:9:"showStaff";s:1:"1";s:15:"displayMultiple";s:1:"1";s:13:"hideUserTitle";b:0;s:17:"showStaffAndOther";b:0;}
    I know this is serialized, although I don't have a key to tell me what means what.
    Converted it looks like...
    Code:
    array (
      'showStaff' => '1',
      'displayMultiple' => '1',
      'hideUserTitle' => false,
      'showStaffAndOther' => false,
    )
    
    So is there a real difference between s:1:"1" and b:0? Well I would think b is a boolean so to match it would be b:1.

    So in code I would do something like
    Code:
    if($options->formatParameter.myCheckbox) { }
    
    As long as the default value is...
    Code:
    a:1:{s:11:"myCheckbox";b:0;}
    
    And my Array suboptions are just "myCheckbox"?

    Also, what about naming them? I know with other stuff you can put
    option = {xen: phrase myPhrase}
    So what about with check boxes?

    Thanks again @Brogan
    I'm trying to catch on quickly here.
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    For the values, s is string and i is integer.
    So these two would be the same:
    • s:1:"1";
    • ;i:1;
    In the template you use options like so:
    Code:
    <xen:if is="{$xenOptions.optionId.optionValue}">
    In PHP like so:
    Code:
    $options = XenForo_Application::getOptions();
    if ($options->optionId['optionValue'])
    or:
    Code:
    if (XenForo_Application::getOptions()->optionId['optionValue'])
    Phrases can be used for labelling checkboxes and radio buttons.
     

Share This Page