Search code examples
symfony1symfony-1.4symfony-forms

How to create grouped form fields in symfony 1.4


I want to group the form fields like field set or simply enclosed by div. My form needs to be look like below

<form>
<div class="step-1">
    Field 1
    Field 2
</div>
<div class="step-2">
    Field 3
    Field 4
</div>
</form>

Graphical example :

Edit : Form class added for reference!

class ProfileForm extends BaseProfileForm
{
  public function configure()
  {
    ..... // other widget configuration
    $this->embedForm('media', new MediaForm());
  }
}

How can I do this in symfony form?


Solution

  • For example:

    In action:

    $this->form = new MyCoolForm()
    

    In templates:

    <form name="form name" id="MyCoolForm" action="<?php echo url_for('action_url') ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
    
     <?php echo $form['name']->render() ?>
     <?php echo $form['name']->renderError(); ?>
    
     <fieldset>
      <legend>Ppassword:</legend>
     <?php echo $form['password']->render() ?>
     <?php echo $form['password']->renderError(); ?>
    
     <?php echo $form['password_again']->render() ?>
     <?php echo $form['password_again']->renderError(); ?>
    <fieldset>
    
     <?php echo $form->renderHiddenFields(); ?>
    </form>
    

    etc...