ZF2 form formatting?

旧街凉风 提交于 2020-01-04 03:01:29

问题


I am using ZF2 and have a form which defines a bunch of elements, and then I render 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 then format these elements to my liking? For example make the radio buttons displayed horizontally rather than vertically and maybe change the location of the label.


回答1:


There's nothing stopping you from formatting them as you have there, you could put the elements inside a list, or andd any additional markup you want to style as you wish.

<?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 wanted to have control over the actual elements/inputs themselves you could 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>


来源:https://stackoverflow.com/questions/14828405/zf2-form-formatting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!