this script is as part of a discussion on : http://www.jeremykendall.net/2008/12/04/zend_form_element_multi-tips-and-tricks/comment-page-1/#comment-16 I have only been using Zend Form for a couple of days - so forgive me if this is a dud tip. I found it useful anyway. --- The Tip: When developping, sometimes i just want to play around with my control code and toggle field names, control actions etc. I just wanted to quickly pass all the variables around from page to page while i experiment. --- A Quick way of generating a form that simply renders the SERVER Request Variables. Create a subclass of Zend_Form with a method like: //set up the form $form_obj = new my_Form_SimpleREQUEST_VARSmimic(); //set up the variables $form_obj->setupREQUESTVarsAsFields(); //render $form_obj->render(); --- here's the fuller example getPropertiesArray(); reset($vars_array); //the conditions could be within the loop but are outside to avoid having too many conditional within the loop if (!($as_hidden_fields)) { //we are showing them up in the form while(list($key,$value) = each($vars_array)) { if (in_array($key,$exclude_keys_arr)) { //we are excluding the var continue; } if (is_array($value)) { $mssg ='myTODO - deal with values as arrays'; throw Exception($mssg); } $element_obj = new Zend_Form_Element_Text($key); $element_obj->setValue($value); $element_obj->setLabel($key); $this->addElement($element_obj); } } else { //they are hidden form inputs while(list($key,$value) = each($vars_array)) { if (in_array($key,$exclude_keys_arr)) { //we are excluding the var continue; } if (is_array($value)) { $mssg ='myTODO - deal with values as arrays'; throw Exception($mssg); } $element_obj = new Zend_Form_Element_Hidden($key); $element_obj->setValue($value); $this->addElement($element_obj); } } } } //....... //then usage is in a controller, for example e.g My Item Editor, can be requested like: http://example.com/manage_items/index.htm?task_action=Choose+Task or http://example.com/manage_items/index.htm?task_action=Choose+Item or http://example.com/manage_items/index.htm?task_action=Create or http://example.com/manage_items/index.htm?Item_id=xyz&CRUD_action=Update&itemcolor=brown&itemflavour=chocolate&task_action=Edit //then the cotroller is called in /index.htm likes so: ---- ///index.htm $my_controller_obj = new my_controller(); $my_controller_obj->indexAction(); ---- //N O T E T H I S I S //N O T A N O F F I C I A L S U B C L A S S O F Zend_Controller_Action //its a cheap, personal, copy ;o) of the ideas class my_controller { //... /** *@desc set up some handy objects */ protected function init() { //we will be using alot of zend . so.. Zend_Loader::registerAutoload(); //get feedback instance $this->users_page_feedback_obj = my_users_page_feedback_singleton::getInstance(); //get the page builder obj - its an object i use to mix up my old 'badly coded Non-MVC' site pages with newer MVC pages $this->page_builder_obj = my_retro_page_builder_sngltn::getInstance(); //handy $this->request_obj = my_request::getInstance(); } /** *@desc the main controller point called by client */ public function indexAction() { //set this so that we know the name of the key/input name that determines the task action (may be different for each controller) $this->task_action_input_name= 'task_action'; //for use elsewhere - but set here to make it easier to edit-in-one-place if amended $this->task_action_options_array = array('Choose Task','Edit','Create','Choose Item'); //pick up the 'task action to do' string from the request $task_action = $this->request_obj->getProperty($this->task_action_input_name); //validate the action that we were passed using Zend $task_action_form_element_obj = $this->get_task_action_form_element_obj(); if (!($task_action_form_element_obj->isValid($task_action))) { $mssgs_arr[] = 'Controller error: Invalid '. $this->task_action_input_name; $mssgs_arr[] = $task_action_form_element_obj->getMessages(); $this->users_page_feedback_obj->addUserMssgArray($mssgs_arr, 'warning'); //echo('its NOT valid action: '.$task_action); return; } else { //its valid - we know we can safely use it as output for our title $this->pg_title2_value_str =$this->task_action_input_name; } //SEE: $this->task_action_options_array for list of avaiable 'case' / 'options' switch ($task_action) { case 'Edit': //...code here break; case 'Create': //...code here break; case 'Choose Item': //...code here break; case 'Choose Task': //follow thru default: //choose a task $this->chooseTaskAction(); } } /** *@desc asks the user to choose which action to do -the default action if no action given - forwarding all the requested vars to whatever task is chosen * (handy if i have not coded the my 'Edit' and 'Create' and 'Choose Item' actions yet ) * */ protected function chooseTaskAction() { //$this->pg_title2_value_str ='Choose Task'; $mssg = 'No task specified'; $this->users_page_feedback_obj->addUserMssg($mssg , 'warning' ); //set up the form $form_obj = new my_Form_SimpleREQUEST_VARSmimic(); //get the zend view object for zend dojo to play with $Z_view_obj = $this->page_builder_obj->get_Z_view_obj(); //register a generic view hlper $form_obj->setView($Z_view_obj); //Zend_Dojo::enableView($Z_view_obj); $form_obj->setAction($this->get_BASE_actions_HREF()) ->setMethod('post'); $form_obj->setAttrib('id', 'choose_task'); //get the task_action $element_obj = $this->get_task_action_form_element_obj(); $form_obj->addElement($element_obj); //stick a button on it $form_obj->addElement(new Zend_Form_Element_Submit('submit')); //pass existing request vars into form fields (telling it NOT to overwrite the elements that i have just made up in the lines above ) $form_obj->setupREQUESTVarsAsFields($this->request_obj,$GPC_array=array('G','P'), $exclude_keys=array($this->task_action_input_name,'submit'), FALSE); $str = $form_obj->render(); //this is just my way of passing my content to be rendered by a view script (registering it with my page_builder_obj) $center_stage_content_obj = new my_UserInterfaceComponent_PrimitiveTypeStringValue($str); $this->page_builder_obj->append_center_stage_content($center_stage_content_obj,$explicit_glue=''); } /** *@desc useful to use in a kind of input_filter way for validation of the variable - not necessarily just for forms */ protected function get_task_action_form_element_obj() { //---------------- $element_obj = new Zend_Form_Element_Select($this->task_action_input_name); $options = $this->task_action_options_array; $options = array_combine($options, $options); //thanks jeremykendall.net $element_obj ->addMultiOptions($options) ->setLabel('Task') ->addValidator(new Zend_Validate_InArray(array_keys($options))); //----------- return $element_obj; } //... } //.......