ZF-1666: Zend_View - form helpers produce extraneous hidden elements

Issue Type: Bug Created: 2007-07-02T12:31:18.000+0000 Last Updated: 2011-01-19T07:58:30.000+0000 Status: Resolved Fix version(s): - 1.5.0 (17/Mar/08)

Reporter: Ralph Schindler (ralph) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_View

Related issues: - ZF-9149

Attachments: - FormCheckbox.php.patch


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.


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:

  • Show some code using the helpers, the XHTML generated
  • Detail what the mis-behaviour is, and what you'd like to see

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.


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

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 == "" ) { = '1px dotted red'; empty_fields = empty_fields + field_array[i]; } else = '1px dotted green'; }

if( empty_fields.length > 2 )
    alert( message );
    return true;

return false;


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?

  • Small sample code exhibiting the behavior
  • Actual output
  • Expected output

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.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.