I suggest you write something like the follow functions based on the Zend_View helpers.
formText($name, $value = null, array $attribs = null)
formPassword($name, $value = null, array $attribs = null)
formLabel($id, $text, array $attribs = null)
formHidden($name, $value = null, array $attribs = null)
formSubmit($name = null, $text = null, array $attribs = null)
formSelect($name, $selected, array $attribs = null, array $options = null)
formCheckbox($name, $default, array $attribs = null, array $options = null)
Then you will never forget/miss something like this again.
<form method="POST" action="<?php echo $PHP_SELF; ?>
<p>
<?php
echo formLabel('login_email', 'Email'), ':',
formText('login_email');
?>
</p>
<p>
<?php
echo formLabel('login_password', 'Password'), ':',
formPassword('login_password');
?>
</p>
<p>
<?php
echo formCheckbox('login_remember'), ' ',
formLabel('login_remember', 'Remember me');
?>
</p>
<p>
<?php
echo formSubmit(null, 'Login');
?>
</p>
</form>
Tip:
- If id not defined in attribs, id is the same as name, except for labels where id is used in the for="$id" attribute and formHidden should not have a default id either.
- formCheckbox writes a formHidden by same name before itself with the negative value, so you get a return value if the checkbox is not checked as well.
- formCheckbox options is an array with the values for checked or unchecked.
- Use a filter with FILTER_VALIDATE_BOOLEAN to read the return value from a checkbox to check if it was marked or not.