Question

I have a zend form:

// Email
    $email = $this->createElement('text', 'email');
    $email->setLabel('Адрес электронной почты:')
        ->addValidator('EmailAddress')
        ->addValidator('StringLength', FALSE, array(6, 30))
        ->setRequired(TRUE);

    // Пароль
    $password = $this->createElement('password', 'password');
    $password->setLabel('Пароль:')
        ->addValidator('StringLength', FALSE, array(6, 30))
        ->setRequired(TRUE);

    // Шрифт капчи
    $fonts = scandir(APPLICATION_PATH . '/other/fonts/');
    $font  = APPLICATION_PATH . '/other/fonts/' . $fonts[rand(2, sizeof($fonts) - 1)];

    // Инициализация капчи
    $captcha = new Zend_Form_Element_Captcha(
        md5($_SERVER["REMOTE_ADDR"] . date('d.m.Y')),
        array('label'    => 'Введите код с картинки:',
              'required' => TRUE,
              'captcha'  => array(
                  'captcha'  => 'Image',
                  'FontSize' => rand(25, 30),
                  'wordLen'  => rand(4, 6),
                  'timeout'  => 300,
                  'font'     => $font,
                  'imgDir'   => 'img/captcha/',
                  'imgUrl'   => '/img/captcha/',
              )));

    $submit = $this->createElement('submit', 'submit_button', array(
                                                                   'label' => 'Enter',
                                                              ));

And I have a my own html code for this form, it contained in view script, but captcha element is dynamic. Is there any way to display only captcha element html code? Like this:

<!-- my html code -->
<?php $this->myForm->captcha; ?>
<!-- my html code -->

Thanks.

Was it helpful?

Solution

yes you can use like below

You need to pass the form to your view script to make it work.

public function someAction()
{
    $this->view->form = new Form_Name(); // form class name
}

in your view script you can receive the elements via

<table>
<tr>
    <td><?= $this->form->getElement('captcha'); ?></td>
</tr>

</table>

let me know if i can help you more.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top