I'm just learning zf2, and the basic tutorial from official document is great. Now, I would like to challenge myself to create multi page form in one page, something like that http://demo.stepblogging.com/multi-step-form/
So, currently I have two forms called "Contact Form" and "Album Form".
The idea is i want to split to 2 forms. The problem is when i finish all the fields on the first form, i'm not sure how to go to next form. I'm not sure i can do the logic at Controller, what i know most of the online tutorials are using javascript to handle the next and back button. Or maybe have better idea?
So this is my Controller page.
public function multipleAction(){
$formOne = new ContactForm();
$formTwo = new AlbumForm();
$formOne->get('next')->setValue('Next');
$request = $this->getRequest();
if($request->isPost()){
$aa = new ContactFilter();
$formOne->setInputFilter($aa);
$formOne->setData($request->getPost());
if ($formOne->isValid()) {
//save session
//maybe display second form or any other solution
}
}
my multiple.phtml page contains 2 forms
<ul id="signup-step">
<li id="contact" class="active">Contact</li>
<li id="album">Album</li>
</ul>
<?php
$form_one = $this->form_one;
//$form_one->setAttribute('action', $this->url('album', array('action' => 'multiple')));
$form_one->prepare();
//echo $_SESSION['name'];
echo $this->form()->openTag($form_one); ?>
<div id="contact-field">
<legend>Contact</legend>
<?php
echo $this->formHidden($form_one->get('id'));
echo $this->formLabel($form_one->get('name')).'<br>';
echo $this->formInput($form_one->get('name'))."<br>";
echo $this->formElementErrors($form_one->get('name'));
echo $this->formLabel($form_one->get('artist')).'<br>';
echo $this->formInput($form_one->get('artist'))."<br>";
echo $this->formElementErrors($form_one->get('artist'));
echo $this->formLabel($form_one->get('address')).'<br>';
echo $this->formInput($form_one->get('address'))."<br><br>";
echo $this->formElementErrors($form_one->get('address'));
echo $this->formSubmit($form_one->get('next'));
echo $this->form()->closeTag($form_one);
?>
<?php
$form_two = $this->form_two;
$form_two->prepare();
echo $this->form()->openTag($form_two); ?>
<div id="album-field" >
<legend>Album</legend>
<?php
echo $this->formLabel($form_two->get('title')).'<br>';
echo $this->formInput($form_two->get('title'))."<br>";
echo $this->formElementErrors($form_two->get('title'));
echo $this->formLabel($form_two->get('artist'))."<br>";
echo $this->formInput($form_two->get('artist'))."<br>";
echo $this->formElementErrors($form_two->get('artist'));
echo $this->form()->closeTag($form_two);
?>