We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1778
    • 659 Posts
    Hi all

    I use FormIt for a contact page. It works fine, but I have a stupid problem with checkboxes...

    I have some checkboxes in my form like :
    <input type="checkbox" name="red" id="red" value="[[+fi.red]]">Red</input>
    <input type="checkbox" name="blue" id="blue" value="[[+fi.blue]]">Blue</input>

    In the mail sent by formit i’d like to know which are the checkboxes "checked"...
    I tried [[+red]] and [[+blue]] , it seems it works that way only with text fields...

    How to do this with checkboxes or radio options ?

    Thanks
      • 24287
      • 14 Posts
      I have the same problem, would really appreciate an answer!
        • 28215
        • 4,149 Posts
        Quote from: anso at May 29, 2010, 08:04 PM

        I have some checkboxes in my form like :
        <input type="checkbox" name="red" id="red" value="[[+fi.red]]">Red</input>
        <input type="checkbox" name="blue" id="blue" value="[[+fi.blue]]">Blue</input>

        In the mail sent by formit i’d like to know which are the checkboxes "checked"...
        I tried [[+red]] and [[+blue]] , it seems it works that way only with text fields...

        How to do this with checkboxes or radio options ?

        Thanks

        For one, your HTML should be this:

            <label><input type="checkbox" name="red" id="red" value="1" [[+fi.red:notempty=`checked="checked"`]] />Red</label>
            <label><input type="checkbox" name="blue" id="blue" value="1" [[+fi.blue:notempty=`checked="checked"`]] />Blue</label>
        


        And then in your email:
        Red: [[+red:if=`[[+red]]`:eq=`1`:then=`Yes`:else=`No`]]
        Blue: [[+blue:if=`[[+blue]]`:eq=`1`:then=`Yes`:else=`No`]]
        

          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 1778
          • 659 Posts
          Thanks this way is probably more efficient than the workaround I found... I wrote a snippet to check the POST value and output the checkbox checked or not ... It works but your way is infinitely more elegant and easy... Thanks a lot.
            • 24287
            • 14 Posts
            Brilliant, thanks a lot!

            I have another problem: On the form should be a checkbox to agree to the terms and conditions, the box should be required to be checked. This is what I have so far but it does not work:

            <input type="checkbox" name="agreement:required" value="1" />


            How does this work?
              • 28215
              • 4,149 Posts
              Add a hidden field at the top of the form with the required validator on it:

              <input type="hidden" name="agreement:required" value="" />
              
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 24287
                • 14 Posts
                Perfect, thank you!
                  • 5438
                  • 3 Posts
                  I used the checkbox code here and it worked great, but how to validate that one box is checked?
                    • 30552
                    • 75 Posts
                    I had the same issue when it came to having a checkbox to agree to the terms and conditions. My question is do I need to have the hidden field at the top like you posted, and have the checkbox field as rabimoe posted? Right now I have this at the top:

                    <input type="hidden" name="agreement:required" />


                    And I have this in the form:

                    <input type="checkbox" name="agreement:required" id="agreement" value="I agree to the terms of your disclaimer." />


                    Upon first trying it, I think it keeps the form from submitting; however, it seems to reload the form, losing all the other values the user has entered, and doesn’t show any error message or anything. What have I done wrong?
                      • 1778
                      • 659 Posts
                      Hello

                      Yes you have to keep both fields, the hidden one to ’keep and transmit’ the submitted value, the not hidden one to display your checkbox on your form.

                      It doesn’t work in your case, transeffect, because you ommit to specify ’ value="" ’ in your hidden field, so it has no value to retain or to submit...

                      Hope this helps
                      Cheers