We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31902
    • 342 Posts
    Willi Waizenegger Reply #1, 13 years ago
    I have an area of a Formit form that has three checkboxes, answering one question. Up until now, these three checkboxes, as a group, have not had any validation attached to them.

    The checkbox group answers the question "I am interested in:" And the checkbox answers has the visitor select "Log Splitters", "Wood Processors" or "Conveyors".

    The thing is that each box, when selected, has to pass either a "1" or a "0", depending on whether it is selected or not. It cannot just pass the name. This is for my client's specific reporting needs.

    Now my client wants to have the group of boxes validate as a group so that at least one, two or three box(s) has/have to be selected.

    In my research on how to validate a group of checkboxes, I came upon a tutorial, located here: http://rtfm.modx.com/extras/revo/formit/formit.tutorials-and-examples/formit.handling-selects,-checkboxes-and-radios under the heading called "Handling Required on Checkboxes". It shows code that looks like this:

    [[!FormIt? &validate=`color:required`]]
    ...
    <label>Color: [[!+fi.error.color]]</label>
    <input type="hidden" name="color[]" value="" />
    <input type="checkbox" name="color[]" value="blue" [[!+fi.color:FormItIsChecked=`blue`]] > Blue
    <input type="checkbox" name="color[]" value="red" [[!+fi.color:FormItIsChecked=`red`]] > Red
    <input type="checkbox" name="color[]" value="green" [[!+fi.color:FormItIsChecked=`green`]] > Green


    The code on my site, on the other hand, because of my need to output either a one or a zero, is the following:

    <div id="choosing_right_machine_form_interested_in">
    <label for="interested_in"><h2>* I am interested in:</h2></label>
    
    <label><input type="hidden" name="splitters" value="0" /><input class="choosing_right_machine_form_interested_in_checkbox_1" type="checkbox" name="splitters" value="1" [[!+fi.splitters:FormItIsChecked=`splitters`]]> Log Splitters</label>
    
    <label><input type="hidden" name="processors" value="0" /><input class="choosing_right_machine_form_interested_in_checkbox_2" type="checkbox" name="processors" value="1" [[!+fi.processors:FormItIsChecked=`processors`]]> Wood Processors</label>
    
    <label><input type="hidden" name="conveyors" value="0" /><input class="choosing_right_machine_form_interested_in_checkbox_2" type="checkbox" name="conveyors" value="1" [[!+fi.conveyors:FormItIsChecked=`conveyors`]]> Conveyors</label>
    
    </div><!-- /choosing_right_machine_form_interested_in -->


    As you can see, in my code, the name=... are different from each other while the value=... are the same (outputting of "1"). As I understand it, the grouped checkbox version in the tutorial needs the name=... of each to be the same as each other in order to group the set for validation.

    So, my question is, how can I utilize my code above, or at least my original "1" or "0" output requirement while having the set validate as having at least one box checked?

    Thank you in advance.

    Revo: 2.2.5-pl
    Formit: 2.1.2-pl



    [ed. note: waizen last edited this post 13 years ago.]
      • 31902
      • 342 Posts
      I'm sorry for the bump, but I'm being pressured to find an answer for this. I appreciate any help.