Formatting a ZF2 form?

I am using ZF2 and have a form that defines a group of elements and then I do it in my phtml like this:

<?php 

$form = $this->form;
$form->prepare();

echo $this->form()->openTag($form);
echo $this->formlabel($form->get('description'));
echo $this->formRow($form->get('radioButton'));
echo $this->form()->closeTag();

?>

      

Which draws a label and a radio button. My question is, how can I format these elements to my liking? For example, radio buttons are displayed horizontally instead of vertically, and possibly change the position of the label.

+3


source to share


1 answer


There's nothing stopping you from formatting them as they are, you can put the items inside the list or any additional markup you want to mark however you want.

<?php 
$form = $this->form;
$form->prepare();

echo $this->form()->openTag($form);
?>
<ul class="form-list">
    <li>
    <div class="form-control">
        <?php echo $this->formlabel($form->get('description')); ?>
        <?php echo $this->formElementErrors($form->get('description')) ?>
        <?php echo $this->formElement($form->get('description')); ?>
    </div>
    <div class="form-control">
        <?php echo $this->formlabel($form->get('radioButton')); ?>
        <?php echo $this->formElementErrors($form->get('radioButton')) ?>
        <?php echo $this->formElement($form->get('radioButton')); ?>
    </div>
    </li>
</ul>
<?php echo $this->form()->closeTag() ?>

      



If you want to have control over the actual items / inputs, you can do something like this:

<label>
    <?php echo $form->get('radioButton')->getLabel() ?>
    <input class="bob" type="radio" 
           name="<?php echo $form->get('radioButton')->getName() ?>"
           value="<?php echo $form->get('radioButton')->getValue() ?>"
    />
</label>

      

+9


source







All Articles