ZF-1666: Zend_View - form helpers produce extraneous hidden elements
Description
Several form helpers produce extraneous hidden elements (such as formCheckbox).
If the developer chooses to produce hidden elements, they should do so with formHidden(), having _hidden automatically implied makes for hard-to-debug xhtml / js / form elements.
Furthermore, while not completely sure at the moment, I dont think this meshes well with the future of xhtml, specifically when it comes to the name and id attributes.
More notes later.
Comments
Posted by Eric Coleman (eric) on 2007-07-02T12:51:17.000+0000
This really should be resolved/fixed, as it really jacks stuff up like checkboxes and radio buttons
Posted by Darby Felton (darby) on 2007-07-30T09:29:22.000+0000
Fix version after 1.0.1.
Posted by Matthew Weier O'Phinney (matthew) on 2007-11-16T10:34:27.000+0000
Scheduled for 1.0.3
Posted by Matthew Weier O'Phinney (matthew) on 2007-11-26T08:42:09.000+0000
Actually, I don't have enough information to close this. I need the following:
I spoke with Paul M. Jones regarding this, and he put in the hidden elements originally to aid browsers that don't have JS -- so that if no option is selected, a value is still returned to the handler (i.e., so the form element key is populated on the server side). This seems like a reasonable goal, but I need to know if it conflicts with HTML specs and/or JS libraries.
thanks!
Posted by Ralf Kramer (ralle) on 2007-12-13T13:06:44.000+0000
I am running into trouble with this useless hidden field in Internet Explorer. IT breaks my JS validation since it generates an empty value where none should be. This empty value prevents my forms to be submitted. But only in IE.
Here is the generated HTML. Angekündigt
Aktiv
Abgelaufen
I do a standard validation for empty values using JS:
/** * Throws an alert if any of the mandatory field is empty * * The param mandatory_fields contains the id's of all mandatory fields. * * @author Ralf Kramer * @param string mandatory_fields: a list of mandatory form fields seperated by a whitespace * @return boolean */ function hasEmptyFields( mandatory_fields, message ) { field_array = mandatory_fields.split( " "); empty_fields = ""; for( i = 0; i < field_array.length; i++ ) { var field = document.getElementById( field_array[i] ); if( field.value == "" ) { field.style.border = '1px dotted red'; empty_fields = empty_fields + field_array[i]; } else field.style.border = '1px dotted green'; }
}
Sure it would be maybe possible to check the type, and if its a radio or a checkbox, the JS could ignore empty fields, but this is not the intention. My explicit intention is to avoid empty fields. If I want to populate a value on the server and really need that hidden field, I can easily create it on my own. But this entire usecase appears to me kind of "constucted"...
Posted by Jordan Ryan Moore (jordanryanmoore) on 2007-12-13T15:03:00.000+0000
Adding patches for FormCheckbox and FormRadio that allow you to choose between generating hidden elements or not, without breaking BC.
Posted by Yang.Acer (adxis) on 2008-01-01T14:51:07.000+0000
Here is my solution with ZF 1.0.2 (applied to my AJAX project) :
Let's see what FormRadio does... ... // build the element if ($disable) { ... } else { ... // is it checked? if ($opt_value == $value) { $radio .= ' checked="checked"; $xhtml = $this->_hidden($name, $value); //my modification, let hidden form has value } ... } ...
(You may find out those code in Zend/View/Helper/FormRadio.php)
Then copy it to ur helper path, change name, add the modification, and put some extra js code to make hidden form value to be updated while radios clicked.
So, when you want to validate it, you only have to check the value of hidden form.
I always assign default value to formRadio, and if u don't do that, you may need to assign value to hidden form while no radio is checked
Posted by Matthew Weier O'Phinney (matthew) on 2008-02-13T08:36:17.000+0000
Resolved in trunk
Posted by Andrei Iarus (poni1111) on 2010-04-14T07:29:45.000+0000
The problem still exists in ZF 1.10.1 AND 1.10.3.
Posted by Andrei Iarus (poni1111) on 2010-04-14T07:36:59.000+0000
Anyway: is this behavior W3 compliant?
Posted by Andras Gyomrey (andras) on 2010-09-02T13:33:26.000+0000
I cant reproduce it too. Please could somebody answer this? My checkbox value is not being saved correctly when i user a different checkedValue and unCheckedValue options.
Posted by Karsten Wutzke (kwutzke) on 2011-01-19T04:49:57.000+0000
This behavior is still present in ZF version 1.11.2. Please reopen it.
Posted by Matthew Weier O'Phinney (matthew) on 2011-01-19T07:58:28.000+0000
For those indicating they are seeing issues, could you please provide the following?
We currently emit hidden values for checkboxes to ensure we get some value on the server side; otherwise, unchecked boxes are not included in the GET and/or POST, which can lead to "missing" values in the form -- often resulting in false negatives when validating.