A Brief Introduction to Zend Form

Example Registration Form - Standalone

setMethod('post'); /** * Here's where I'm setting the options for the interests checkboxes and * the referral select element. * * Notice that I'm using Zend_Form's fluid interface to add the * Zend_Validate_InArray validator to each element * * The use of array_merge and array_combine is one of my tricks and tips * from my Zend_Form_Element_Multi - Tips and Tricks blog post (http://bit.ly/bEZl37) */ $form->getElement('interests') ->addMultiOptions(array_combine($interests, $interests)) ->addValidator(new Zend_Validate_InArray($interests)); $form->getElement('referral') ->addMultiOptions(array_merge(array('Please make a selection . . .'), array_combine($referral, $referral))) ->addValidator(new Zend_Validate_InArray($referral)); /** * If the request is a get request, then the form hasn't been * submitted and should be displayed. */ if (strtolower($_SERVER['REQUEST_METHOD']) == 'get') { // Render form echo $form->render($view); } else { /** * If the form doesn't pass validation, it should be displayed * again with current field values and error messages */ if (!$form->isValid($_POST)) { // Failed validation - render form with errors echo $form->render($view); } else { /** * The form has passed validation and the validated and filtered form values * are ready for use/manipulation/processing. * * For the purposes of this example, the validated & filtered form values * are being dumped to the view. */ Zend_Debug::dump($form->getValues()); } } ?>