It is quite easy to start using a framework as an easy way to manage your url rewriting, and forget about all the added functionality provided by the framework. An ideal example of this is when making forms. You can create a form manually and that is perfectly valid, but if you use the framework it will help you filter and validate the form with very little effort!
Zend_Form
The framework provides a Zend_Form class that you can extend to easily create forms and assign validation and filters too with a few simple lines of code. Name the elements the same as the db then the populate will work with one line of code also.
In your Application folder create a Forms folder
This is an example form:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php class Form_CreateEmail extends Zend_Form { public function __construct($options = null) { parent::__construct($options); $this->setName('createemail'); $title = new Zend_Form_Element_Text('title'); $title->setLabel('Subject') ->setRequired(true) ->addFilter('StripTags') ->addFilter('StringTrim') ->addValidator('NotEmpty'); $info = new Zend_Form_Element_Textarea('info'); $info->setLabel('Email Content') ->setAttribs(array('rows' => 12, 'cols' => 79)); $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('id', 'submitbutton'); $this->addElements(array($title, $info, $submit)); } } ?> |
You can then call it from your controller like this:
1 2 3 | $form = new Form_CreateEmail(); $form->submit->setLabel('Add'); $this->view->form = $form; |
And display it from you view using
1 | echo $this->form; |
If you want this to be included on everypage you could create a new helper file
in your views folder create a helpers folder and create a myHelper.php file
1 2 3 4 5 6 7 8 9 10 11 | class Zend_View_Helper_MyHelper { function myHelper() { $form = new Form_CreateEmail(); $form->submit->setLabel('Add'); return = $form; } } |
This could be output from your layout using:
1 | <?php echo $this->MyHelper(); ?> |
Hope this helps someone



