O
O
Oklick2016-08-26 01:46:05
Zend Framework
Oklick, 2016-08-26 01:46:05

How to get the captcha image from the form element separately from the input in zf2?

Good day.
When developing the site, the following problem arose:
when using the "captcha" form element (standard captcha from zf2)

<div><?php
echo $this->formElement($registerForm->get('captcha'));
?></div>

The whole code is inserted (i.e. the image together with the input in one div), but I need to separate the captcha image with the input into different divs.
Here is an example of how it is inserted now:
<div>
    <img width="120" height="50" alt="" src="/images/captcha/054fbf1c546eb312aa0dc72980e573b8.png">
    <input name="captcha[id]" type="hidden" value="054fbf1c546eb312aa0dc72980e573b8">
    <input name="captcha[input]" type="text">
</div>

What I need is something like this:
<div>
    <img width="120" height="50" alt="" src="/images/captcha/054fbf1c546eb312aa0dc72980e573b8.png">
</div>
<div>
    <input name="captcha[id]" type="hidden" value="054fbf1c546eb312aa0dc72980e573b8">
    <input name="captcha[input]" type="text">
</div>

Is it possible somehow, with the help of this appeal: Pull out a separate picture and a separate input? Thanks in advance.
$this->formElement($registerForm->get('captcha'));

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2016-08-26
@Oklick

Pay attention to the separator option , which is in the base class of all captcha view helpers. You need to give it a value '</div><div>'.

<div>
<?php
    $captcha = $registerForm->get('captcha');
    echo $this->formCaptchaImage()->setSeparator('</div><div>')->render($captcha);
?>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question