We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37550 ☆ A M B ☆
    • 711 Posts
    onesmarthost Reply #1, 19 years ago
    Hi All,

    I’m spent quite some time trying to work out how to add checkboxes to my eform the main requirement is that one or more checkboxes must be clicked but the form cannot be submitted with no checkbox’s selected.

    I’ve tried the following code, but this shows the validation message as required when only 1 item is clicked.


    <p>
    <Input Type="Checkbox" Name="allowed[]" eform="Allowed Venues::1" Value="1">test

    <Input Type="Checkbox" Name="allowed[]" Value="2">test 2

    <Input Type="Checkbox" Name="allowed[]" Value="3">test 3

    </p>

    Any tips?

    Aaron

      http://www.onesmarthost.co.uk
      UK MODX Hosting with love.
      • 33372
      • 1,611 Posts
      That’s odd. The code that you’ve posted should work. I’ve used checkboxes in eForm like this a lot, and I’ve never seen that problem.

      I wonder if perhaps there’s something specific about the way that eForm parses your form code that’s causing it not to register this field properly. You’re doing it a little bit differently than I generally do in that you have the value after the eform tag and you’re using non-XHTML syntax by capitalizing words in the tag. Maybe you should just try changing those things, so your code would be:


      <p>
      <input type="checkbox" name="allowed[]" value="1" eform="Allowed Venues::1"/>test

      <input type="checkbox" name="allowed[]" value="2" />test 2

      <input type="checkbox" name="allowed[]" value="3" />test 3

      </p>

      I know it seems like a small change, but given that eForm is parsing your form chunk and looking for specific patterns, you never know what might throw it off.
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 30223
        • 1,010 Posts
        Quote from: ZAP at Sep 15, 2007, 06:33 PM

        That’s odd. The code that you’ve posted should work. I’ve used checkboxes in eForm like this a lot, and I’ve never seen that problem.

        I wonder if perhaps there’s something specific about the way that eForm parses your form code that’s causing it not to register this field properly. You’re doing it a little bit differently than I generally do in that you have the value after the eform tag and you’re using non-XHTML syntax by capitalizing words in the tag. Maybe you should just try changing those things, so your code would be:

        I know it seems like a small change, but given that eForm is parsing your form chunk and looking for specific patterns, you never know what might throw it off.

        Hit the nail right on the head! eForm doesn’t care about the order of attributes but it is very picky about casing. I bet using zap’s markup will get you what you want. Just for the sake of it before you change the markup set the &debug parameter to 2 or 3 and have a look at the fields array. You probably will see no values in there for the check box.
          • 37550 ☆ A M B ☆
          • 711 Posts
          onesmarthost Reply #4, 19 years ago
          Cheers for the help, it was the casing causing the problem.

          I switched on debug and there was no values for the checkboxes but once I fixed the casing all was fine.

          Thanks

          Aaron smiley
            http://www.onesmarthost.co.uk
            UK MODX Hosting with love.
            • 7253
            • 97 Posts
            I had a similar problem - which this thread solved, thanks - but I have a related issue:

            If you don’t tick any of the checkboxes, the input controls get a ’class="required"’, but their associated labels don’t. This means that any CSS classes (maybe to change background colour) won’t apply to these checkbox labels.

            This is a bug, I think, or am I doing something wrong?
              • 30223
              • 1,010 Posts
              You are correct. This is a bug of sorts.. eForm, as it is, can not work out what label belongs to which checkbox. It sets the correct placeholders but then fails to set values for them. Attached is a version with a quick workaround based on eForm 1.4.4. This is not an official release but it will solve your immediate problem.

              In your form you will need to set the id for each checkbox and use the for attribute in each accompanying label:
              <input type="checkbox" value="green" name="checkMe[]" id="checkme1" eform="Check Me::1" /><label for="checkme1">Green</label><br />


              edit: added eform.inc.php.gz