admin
Guest
|
 |
« on: November 20, 2009, 12:13: PM » |
|
Creating a new form within the Zend framework. You can run into a bit of trouble with the display text (value attribute) for the submit element when it comes to invoking the Zend_Form_Element_Submit() method. Like usual, when it comes to frameworks and other types of plug-ins, things don’t work out like you normally would think they should.
Web application developers are constantly battling the inconsistent semantics from the syntax. The same concept as out of the norm…
Code Examples: The below code represents the submit buttons display text. It has always been that the input type submit element’s attribute of value is what displays the button’s text however when using the Zend framework’s Zend_Form class, you must use the setLabel method. See where lines 8 and 9 in Red are commented out, where normally one would think to set the attribute for value to show the display? You may have tried both methods the setValue and setAttrib and both to your surprise had no effect to the button’s display text (normally using the value attribute).
The Fix: In order to overcome this minor problem, you must use the setLabel method which also generates the label tags for each form element. So the ZFW requires that you use this same method to set the text display within the button.
< ?php class LoginForm extends Zend_Form { public function __construct($options = null) { $submit = new Zend_Form_Element_Submit('submit'); //$submit->setValue('Login'); //$submit->setAttrib('value', 'Login'); $submit->setLabel('Login'); $this->addElements(array($username, $password, $submit)); } } ?>
Conclusion Even though this problem could potentially throw off many web developers that are new to this framework, it still has it’s purpose in their design logic. They must have designed it this way to keep the consistency within their own framework. The setLabel method is used on almost every form element so it would be consistent enough to use this same method on the submit type input elements. Hope this helps everyone that had encountered this same issue.
|