php - ZF2 - Separating one form in many tabs -


i need help.. have unique form multiples fieldsets, , need separate fieldsets in tabs..

so, tried in view (form variable whole form):

$form = $this->form; $customfieldset = $form->get('customfieldset'); $form->remove('customfieldset'); 

it works, fieldset form in $customfieldset.. but, can't render this! when try:

echo $this->form($customfieldset); //or echo $this->forminput($customfieldset); //or $this->formcollection($customfieldset); 

none of works..

i'm doing right? how can it?

thank much.

to achieve result want (using form across several tabs, better construct form differently, based on tab's number. example, form constructor method below:

<?php namespace application\form;  use zend\form\form;  // form model class yourform extends form {   // constructor.      public function __construct($tabnum)   {     // define form name     parent::__construct('contact-form');      // set post method form     $this->setattribute('method', 'post');      // create form fields here ...       if($tabnum==1) {        // add fields first tab     } else if($tabnum==2) {        // add fields second tab     }    } } 

in example above, pass $tabnum parameter form model's constructor, , constructor method creates different set of fields based on value.

in controller's action, use form model below:

<?php namespace application\controller;  use application\form\contactform; // ...  class indexcontroller extends abstractactioncontroller {    // action displays form   public function someaction() {      // tab number post     $tabnum = $this->params()->frompost('tab_num', 1);             // create form     $form = new yourform($tabnum);      // check if user has submitted form     if($this->getrequest()->ispost()) {        // fill in form post data       $data = $this->params()->frompost();                   $form->setdata($data);        // validate form       if($form->isvalid()) {          // filtered , validated data         $data = $form->getdata();          // ... validated data ...          // if tabs shown, redirect user thank page         if($tabnum==2) {           // redirect "thank you" page           return $this->redirect()->toroute('application/default',              array('controller'=>'index', 'action'=>'thankyou'));         }       }                 }       // pass form variable view     return new viewmodel(array(           'form' => $form,           'tabnum' => $tabnum        ));   } } 

in view template, use following code:

<form action="">   <hidden name="tab_num" value="<?php echo $this->tabnum++; ?>" />   <!-- add other form fields here --> </form> 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -