ZF-5056: value of button is empty
Description
I don't know why the code was added in the file,but the value of button always is empty.
file: library\Zend\Form\Decorator\ViewHelper.php :197
code:
if (stristr($type, 'button')) {
$element->content = $element->getLabel();
return null;
}
Comments
Posted by Matthew Weier O'Phinney (matthew) on 2008-11-24T19:52:46.000+0000
I needmore information. I know why the code reads that way, but I need to know a) what code you wrote, b) what your expected result was, and c) what the actual result was. Without that, I have no idea what you want fixed.
Posted by Anselm Föhr (anselm) on 2009-04-29T06:37:40.000+0000
The Problem is that you can't setValue for a button:
Expected output when rendering the form: a button with value attribute.
Actual result: a button without value attribute.
Posted by Matthew Weier O'Phinney (matthew) on 2009-04-29T07:35:38.000+0000
Hmm.. differs from in this regard, as the button label for an is its value. As such, we used setLabel() to set the value for buttons -- but then does not get a value attribute.
I'll triage this following the 1.8.0 release.
Posted by Michaël Perrin (sweedymick) on 2009-07-17T07:39:12.000+0000
While this behavior is accurate for , it is not for as this one handles both a label and a value. At its current state, the Zend Framework makes no use of the defined value of when rendering the element, although there is some code about it in the FormButton helper :
The best way to avoid this problem is to apply this patch:
Just as a little warning, don't forget that when submitting the form, Internet Explorer 6 and 7 send the inner HTML of the button tag instead of the content of the value attribute, as described here : http://msdn.microsoft.com/en-us/library/… . Internet Explorer 8 doesn't, but for older version some workarounds need to be implemented. So if the value attribute is defined, the submitted data will defer for Internet Explorer than what it is currently.
Posted by Christian Albrecht (alab) on 2010-04-05T04:24:02.000+0000
Another problem arises when you validate a submitted Form with mixed and
When submitting the Form by hitting "baz", "foo" will not be submitted, hence the Value empty.
After Validation will be rendered.
Posted by Olivier Mellinger (parktrip) on 2010-04-26T00:29:23.000+0000
Is there any reason for that little bug not to be fixed ? Because it's quite annoying if we want to deploy html5 websites
Posted by Thomas G. (fernandorey) on 2011-02-17T09:42:26.000+0000
If you need to check if a button was clicked, isChecked() will not work because of this bug.
Instead, you should use
Posted by Thomas (mctom987) on 2012-03-06T00:53:59.000+0000
Bump. Please fix this. Zend_Form_Element_Button::setValue() is ignored, yet Zend_View_Helper_FormButton::setValue() works as expected.
$submit = $this->createElement('button', 'submit'); $submit->setAttrib('type', 'submit') ->setAttrib('value', 'save') ->setLabel('Save') ->setDecorators(array('ViewHelper')); // Save
$this->getView()->formButton('submit', 'save', array('type' => 'submit')); // save
Posted by Thomas (mctom987) on 2012-03-06T00:59:58.000+0000
Bump. Please fix this. Zend_Form_Element_Button::setValue() is ignored, yet Zend_View_Helper_FormButton::setValue() works as expected. I'm using ZF 1.11.11 and this is still an issue.
$submit = $this->createElement('button', 'submit'); $submit->setAttrib('type', 'submit') ->setAttrib('value', 'save') ->setLabel('Save') ->setDecorators(array('ViewHelper')); // Save$this->getView()->formButton('submit', 'save', array('type' => 'submit')); // saveSorry for the DP, couldn't find an "edit".
Posted by Claude Duvergier (cduv) on 2012-12-19T17:53:12.000+0000
Still an issue on version 1.12.1: any reason not to fix this by applying Michaël Perrin or Thomas's patch?
Posted by Frank Brückner (frosch) on 2012-12-20T16:16:40.000+0000
@Claude Unit test are missing, but I will fix this.
Posted by Frank Brückner (frosch) on 2012-12-21T08:42:05.000+0000
@Claude You forgot the comment from Christian Albrecht.
Posted by Frank Brückner (frosch) on 2012-12-21T08:47:18.000+0000
My suggestion.
Posted by Rob Allen (rob) on 2012-12-22T11:49:39.000+0000
Frank's patch looks good to me. Please commit to trunk and release-1.12.
Posted by Frank Brückner (frosch) on 2013-01-08T08:33:15.000+0000
Fixed on trunk (25188) and release-1.12 (25189)