We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29076
    • 615 Posts
    I can check a checkbox, but as soon as the form validation fails the checked checkboxes gets unchecked. My call is:
    [[!FormIt? &hooks=`spam,email,redirect` &emailTpl=`KursYoga` &emailTo=`[email protected],[email protected]` &emailSubject=`Påmelding til Yogakurs` &redirectTo=`13`]] 
                <h2>Kryss av for valgt kurs</h2>              
                <p>[[+fi.error.error_message]]</p>              
                <form action="[[~[[*id]]]]" method="post" class="form">  
                    <input type="hidden" name="nospam:blank" value="" />
                    <input type="checkbox" name="k1" id="k1" value="1" [[+fi.k1:notempty=`checked="checked"`]] />  
                    <input type="submit" value="Send påmelding" />
                </form>

    Is there a way to make the checked boxes still be checked after validation failure?

    MODx Rev 2
    FormIt 1.1.7 pl

    Thanks. smiley
      I think, thererfor I am! But what I am, and why...?
      • 1778
      • 659 Posts
      Hi,
      You should add *before* your checkbox field an hidden field with the same name as the checkbox and an empty value to ensure to pass the good value....

      <form action="[[~[[*id]]]]" method="post" class="form">  
        <input type="hidden" name="nospam:blank" value="" />
        <input type="hidden" name="k1" value="" />  // ADD THIS LINE ...
      
        <input type="checkbox" name="k1" id="k1" value="1" [[+fi.k1:notempty=`checked="checked"`]] />  
        <input type="submit" value="Send påmelding" />
      </form>
      


      Hope this helps
      Cheers
        • 29076
        • 615 Posts
        Thank you for your answer. smiley
        Unfortunately it didn’t help. If you want to take a closer look, you can see it here: verketyoga.no/p%C3%A5melding.html/ (I’m not done styling it yet). (Please don’t send a validated form.)
          I think, thererfor I am! But what I am, and why...?
          • 1778
          • 659 Posts
          Hello Sylvaticus,

          You ommit the link I guess wink
            • 29076
            • 615 Posts
            Sorry, and thanks. smiley It’s there now. http://verketyoga.no/p%C3%A5melding.html (Added the link in this post to day for easier access.)
              I think, thererfor I am! But what I am, and why...?
              • 1778
              • 659 Posts
              I can’t see the link... Same player shoot again ? Sorry it’s in your previous post ! I got it
                • 1778
                • 659 Posts
                Ok I think I see the problem

                Your code is
                <form action="påmelding.html" method="post" class="form">  
                  <input type="hidden" name="nospam:blank" value="" /> 
                   <input type="hidden" name="k1:notempty=`checked="checked"`" value=""]] /> 
                


                The hidden field must have only the name of the checkbox and its validators if there are some (i.e name="k1:required") (in your case the part after the semicolumn is not a validator but an output filter), so your code should be this:

                <form action="påmelding.html" method="post" class="form">  
                   <input type="hidden" name="nospam:blank" value="" /> 
                   <input type="hidden" name="k1" value="" /> // THIS LINE MUST STAY AS IT IS
                   <input type="hidden" name="k2" value="" /> // HERE THE SAME FOR THE CHECKBOX K2
                
                // some stuff here (table)
                
                // your checkbox called k1
                  <label> 
                    <input type="checkbox" name="k1" id="k1" value="1" [[+fi.k1:notempty=`checked="checked"`]]/> 
                  </label> 
                
                // some stuff here
                
                //your checkbox called k2
                <input type="checkbox" name="k2" id="k2" value="1" [[+fi.k2:notempty=`checked="checked"`]] />
                
                //if you want to make it required
                
                <input type="checkbox" name="k2:required" id="k2" value="1" [[+fi.k2:notempty=`checked="checked"`]] />
                
                // don't forget to modify the hidden one like that
                <input type="hidden" name="k2:required" value="" /> // PUT THIS LINE INSTEAD OF THE ORIGINAL ONE TO HAVE k2 REQUIRED
                
                


                Hope this time it will work as you expect, let me know

                Cheers
                  • 29076
                  • 615 Posts
                  Thanks again so much for your help. Unfortunately it still doesn’t work. (The code <input type="hidden" name="k1:notempty=`checked="checked"`" value=""]] /> was something I tried after I tried your code.

                  One good side-effect: the validation for checkboxes, as you described it, works.
                    I think, thererfor I am! But what I am, and why...?
                    • 1778
                    • 659 Posts
                    Hello,

                    What else exactly does not work ? Or what is what you expect?

                    I understood you had a problem with keeping the checkboxes checked if validation fails, that’s done...

                    Cheers
                      • 29076
                      • 615 Posts
                      No, thats exactly whats wrong, the checkboxes doesn’t stay checked. When I click (check) for example K1, and then click Submit, the validation-error messages comes, AND the checked K1 gets unchecked. And I want it to stay checked (of cource) smiley.
                        I think, thererfor I am! But what I am, and why...?