We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22278
    • 8 Posts
    Onno Cleijpool Reply #1, 16 years ago
    Hey all,

    I feed a bit stupid asking this question, but I have teared my hear out for a day, and still got nowhere.
    I have installed Revo and build a nice login page. I also build a profile page so the user can add/change its profile. So far so good....now the gender setting....I would like to have a radio or selectbox to do this. So far I have:

    <select name="gender" id="gender">
    <option value="1">Male</option>
    <option value="2">Female</option>
    </select>

    No rocket science so for, but now I would like to use the [[+gender]] field to select the right option.

    I can use:
    <select name="gender" id="gender">
    <option value="1" select>Male</option>
    <option value="2">Female</option>
    </select>
    But then everybody is male!

    Is there anybody who can help me with the secret formula do it flips to male in stead [[+gender]] == 1 and flips to female if [[+gender]]==2?


    Thanks
    Onno
      • 22278
      • 8 Posts
      Onno Cleijpool Reply #2, 16 years ago
      After a restless night, I figured out how to solve this. I don’t know if this is the best (or the) way to do this, but it works for me.

      I figured out, I needed a snipped to execute the PHP if then statement for me. So In the template chunk on the spot where the radio buttons should appear, I included [[!MaleFemale? &gender=`[[+gender]]`]] So basically I call a new snippet and send the gender value to it.

      Then I created the snippet "MaleFemale and included the following:

      <?php
      if ($gender == 2) {echo "
      <label><input name=’gender’ type=’radio’ value=’1’ >Male</label>
      <label><input name=’gender’ type=’radio’ value=’2’ checked >Female</label>";}
      else {echo"
      <label><input name=’gender’ type=’radio’ value=’1’ checked >Male</label>
      <label><input name=’gender’ type=’radio’ value=’2’ >Female</label>";}
      ?>

      It works!

      Ps I don’t like the exploded approach, so if anybody still have a better suggestion, feel free to share.

      Onno
        • 1778
        • 659 Posts
        Hello

        You can easily do that using input/output modifiers (in Revo) or PHx (in Evo).

        Assuming you are using Revo you can do something like that:
        <select name="gender" id="gender" value="[[+gender]]">
        <option id="male" value="1" [[+gender:is=`1`:then=`selected="selected"` ]]>Male</option>
        <option id="female" value="2" [[+gender:is=`2`:then=`selected="selected"` ]]>Female</option>
        </select>
        


        This should work...
        Hope this helps
        Cheers
          • 22278
          • 8 Posts
          Onno Cleijpool Reply #4, 16 years ago
          Thank you so much anso, this is exactly what I was looking for. This is in line with clean MODx coding!
          SOLVED grin