jshuter / php-form-builder-class

Automatically exported from code.google.com/p/php-form-builder-class
GNU General Public License v3.0
0 stars 0 forks source link

Checkbox HTML5 validation #173

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. make a checkbox group with 2 options which requires validation
2. try to submit the form without checking both checkboxes

What is the expected output? What do you see instead?
It should let me submit with 1 or 2 checked, and fail with 0 checked.
It actually fails on 0 and 1 checked and only allows 2 checked

What version of the product are you using? On what operating system?
3.0 5.3

Original issue reported on code.google.com by mo...@rustybrick.com on 14 Sep 2012 at 5:49

GoogleCodeExporter commented 8 years ago
Thanks for the bug report.  I was able to recreate this issue and be providing 
a patch in the next few days (hopefully today).

- Andrew

Original comment by ajporterfield@gmail.com on 15 Sep 2012 at 1:42

GoogleCodeExporter commented 8 years ago
Which web browser are you using?  In Firefox on Mac, the required HTML5 
attribute applies validation to each checkbox in the group - meaning you would 
get an error if any of the checkboxes were left unchecked.

With radio buttons, the required attribute applies to the group and not each 
radio button - meaning you would get an error only if all radio button were 
left unchecked.

Are you seeing the same behavior in your browser?

- Andrew

Original comment by ajporterfield@gmail.com on 15 Sep 2012 at 2:05

GoogleCodeExporter commented 8 years ago
The fix for this issue is to edit PFBC/Element/Checkbox.php.  Near the bottom 
of the render method, you'll see a line within the for loop echoing each 
option's label and input tag.  In that line, the getAttributes method is 
called.  That method call currently look like this...

$this->getAttributes(array("id", "value", "checked"))

You need to update it to include "required" in the array.  The final result 
looks like this...

$this->getAttributes(array("id", "value", "checked", "required"))

This will prevent the required HTML5 attribute from being added to the input 
tag.

- Andrew

Original comment by ajporterfield@gmail.com on 15 Sep 2012 at 5:29

GoogleCodeExporter commented 8 years ago
And then pfbc will validate correctly server side right?

Original comment by mor...@gmail.com on 16 Sep 2012 at 12:37

GoogleCodeExporter commented 8 years ago
Yep, you got it.  The latest revision (r570) contains a fix for this bug.  So, 
if you don't want to manually edit the source, you can just export the 
project's trunk with...

svn export http://php-form-builder-class.googlecode.com/svn/trunk/ 
pfbc3.0-php5.3

- Andrew

Original comment by ajporterfield@gmail.com on 16 Sep 2012 at 3:13