I have a select dropdown menu on one DIV and want the user to make a selection and when that happens below a different form appears on DIV below based on the choice they selected. Want to make this without having to do a post (page refresh).
Here is my /views/scripts/postjob/index.phtml
<div id="post_job">
<?php echo $this->form->setAction($this->url()); ?>
</div>
<div id="display">
</div>
Here is the controller
class PostJobController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$form = new Application_Form_DivForm();
$business = new Application_Form_BusinessCardForm();
$calendar = new Application_Form_CalendarForm();
$brochure = new Application_Form_BrochureForm();
$this->view->form=$form;
}
}
Now here is my /forms/DivForm
class Application_Form_DivForm extends Zend_Form
{
public function init()
{
$this->setName("Business Card");
$this->setMethod('post');
$this->addElement('select','type',
array(
'label' => 'Post Job (select)',
'onchange' => 'showForm(this.value)',
'value0' => 'Select',
'multiOptions' => array(
'value1' => 'Business Cards',
'value2' => 'Calendars',
'value3' => 'Brochures',
),
)
);
}
}
I am sure there are more than one way to do this but trying to find something simple. Perhaps just passing back a variable to the controller from the index.phtml and then i can do an if statement and select what form to include on the view.
Was able to solve this problem using a AJAX to post back to another controller action and then returning data back to AJAX. Still have to figure out how to submit all these subforms when they are all dynamically created.