1

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.

4

1 回答 1

2

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.

于 2013-06-06T08:58:29.830 回答