Today I was creating a new login form within the Zend framework. I had ran into a bit of trouble with the display text (value attribute) for the submit element when it came to invoking the Zend_Form_Element_Submit() method within my model. 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…
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 I had comment line 8 and 9 where normally you would think to set the attribute for value to show the display? And yes these are built in methods that are part of the framework. I had tried both methods the setValue and setAttrib and both to my surprise had no effect to the button’s display text (normally using the value attribute).
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.
class LoginForm extends Zend_Form
public function __construct($options = null)
$submit = new Zend_Form_Element_Submit('submit');
$this->addElements(array($username, $password, $submit));
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. I hope this helps everyone that had encountered this same issue.