We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30319
    • 406 Posts
    I have two radio buttons on a form, with field:required in the &validate section.
    When the first button is clicked the error message still displays.
    If the second button is clicked no error appears.
    Should I *not* use zero (0) as one of the radio button values??
    Thank you, Tom

    Snippet call is:

    [[!Profile? &prefix=`usr.`]]
    [[!FormIt?  
    &hooks=`emailSelector,email,redirect`  
    &emailTpl=`board.email`
    &emailSubject=`Message` 
    &emailTo=`[[+emailAddresses]]`
    &emailCC=`[[+usr.email]]`
    &emailBCC=``
    &emailFrom=`[[+usr.email]]`
    &emailFromName=`[[+usr.fullname]]`
    &redirectTo=`72`
    &validate=`whom:required,text:required:stripTags`
    ]]
    


    Form code is:

    <p>
    <label>Choose whom to email: [[!+fi.error.whom]]</label>
    <input type="hidden" name="whom" value="" />
    <input type="radio" name="whom" value="0" [[!+fi.whom:FormItIsChecked=`0`]] > First Person
    <input type="radio" name="whom" value="1" [[!+fi.whom:FormItIsChecked=`1`]] > Second Person
    <input type="radio" name="whom" value="2" [[!+fi.whom:FormItIsChecked=`2`]] > Both People
    </p>
    


    <?php
    $group[0] = 't@barcom'; // First Person
    $group[1] = '[email protected]'; // Second Person
    $group[2] = '[email protected], [email protected]'; // Both People
    $userChoice = $hook->getValue('whom');
    $choice = intval($userChoice); // convert string in integer
    $hook->setValue('emailAddresses',$group[$choice]);
    return true;
    

    This question has been answered by TomMLS. See the first response.

    • Silent Works Reply #2, 12 years ago
      I haven't really looked into how the validation function works but I would suggest starting your count from 1. I would think 0 is as good as false.
      • discuss.answer
        • 30319
        • 406 Posts
        Can't hurt to try changing 0 to 1 and the whole number sequence to 1, 2, 3...seems to work...I thought php and stuff like this was/is zero-based. Marked this solved and will return if necessary. [ed. note: TomMLS last edited this post 12 years ago.]