How to reproduce one form into which are put a div

2019-09-14 19:29发布

问题:

Is it possible to reproduce this form using Zend\Form\Form, please ?

<form method="post" action="add">
    <div class="form-group">
        <label for="identifiant">Identifiant</label>
        <input type="text" class="form-control" name="identifiant" id="identifiant" value="" placeholder="Entrez l'identifiant" />
    </div>
    <button type="submit" class="btn btn-primary">Ajouter</button><a href="../compte" style="margin-left:5px;">Retourner à la liste</a>
</form>

Because I wasn't able to find how to write a div using that api into which I include those tags. And the same thing to the button.

Thanks in advance!

回答1:

Yes, it's possible. The easiest way is to simply include the additional markup in your view:

<?=$this->form()->openTag($this->form)?>

<div class="form-group">
    <?=$this->formRow($this->form->get('identifiant'))?>
</div>

<?=$this->formButton($this->form->get('etc...'))?>

<?=$this->form()->closeTag()?>

If you want the helpers to include the markup automatically this is also possible, but you'd need to extend the formRow helper yourself to get it to to this (quite a bit more involved).

PS: You've basically asked the same question as you did the other day. Questions where you show what you're trying to achieve and what you've tried are much more likely to get a good reply on StackOverflow than "is this possible?" questions like this one.