ZF2 - 在许多选项卡中分隔一个表单

I need a help.. I have a unique form with multiples fieldsets, and i need separate some fieldsets in tabs..

So, i tried in the view (form is my variable with the whole form):

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

It works, my fieldset form is in $customFieldset.. but, i can't render this! When a try:

echo $this->form($customFieldset);
//OR
echo $this->formInput($customFieldset);
//OR
$this->formCollection($customFieldset);

None of that works..

I'm doing right? How i can do it?

Thank very much.

To achieve the result you want (using the form across several tabs, it is better to construct the form differently, based on the tab's number. For example, your form constructor method would look like below:

<?php
namespace Application\Form;

use Zend\Form\Form;

// A form model
class YourForm extends Form
{
  // Constructor.   
  public function __construct($tabNum)
  {
    // Define form name
    parent::__construct('contact-form');

    // Set POST method for this form
    $this->setAttribute('method', 'post');

    // Create the form fields here ...  
    if($tabNum==1) {
       // Add fields for the first tab
    } else if($tabNum==2) {
       // Add fields for the second tab
    } 
  }
}

In the example above, you pass the $tabNum parameter to form model's constructor, and the constructor method creates a different set of fields based on its value.

In your controller's action, you use the form model as below:

<?php
namespace Application\Controller;

use Application\Form\ContactForm;
// ...

class IndexController extends AbstractActionController {

  // This action displays the form
  public function someAction() {

    // Get tab number from POST
    $tabNum = $this->params()->fromPost('tab_num', 1);       

    // Create the form
    $form = new YourForm($tabNum);

    // Check if user has submitted the form
    if($this->getRequest()->isPost()) {

      // Fill in the form with POST data
      $data = $this->params()->fromPost();            
      $form->setData($data);

      // Validate form
      if($form->isValid()) {

        // Get filtered and validated data
        $data = $form->getData();

        // ... Do something with the validated data ...

        // If all tabs were shown, redirect the user to Thank You page
        if($tabNum==2) {
          // Redirect to "Thank You" page
          return $this->redirect()->toRoute('application/default', 
            array('controller'=>'index', 'action'=>'thankYou'));
        }
      }            
    } 

    // Pass form variable to view
    return new ViewModel(array(
          'form' => $form,
          'tabNum' => $tabNum
       ));
  }
}

In your view template, you use the following code:

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