За последние 24 часа нас посетили 18987 программистов и 1637 роботов. Сейчас ищут 825 программистов ...

Подскажите

Тема в разделе "Вопросы от блондинок", создана пользователем Mixik_sp, 22 авг 2010.

  1. Mixik_sp

    Mixik_sp Активный пользователь

    С нами с:
    16 фев 2010
    Сообщения:
    24
    Симпатии:
    0
    Привет всем! Нужна помощь знающих людей. Незнаю как совместить скрипт каптчи и контролера при условии что шаблон написан в смарти register.tpl.
    Капча
    PHP:
    1.  
    2. <?php
    3. /*
    4.  * To change this template, choose Tools | Templates
    5.  * and open the template in the editor.
    6.  */
    7.  
    8. /**
    9.  * Description of CaptchaController
    10.  *
    11.  * @author Елена
    12.  */
    13. class CaptchaCdController extends Zend_Controller_Action
    14. {
    15.     public function captchaAction()
    16.     {
    17.         $session = new Zend_Session_Namespace('captcha');
    18.  
    19.         $configfile = Zend_Registry::get('configfile');
    20.  
    21.         $captcha = new Zend_Captcha_Image(array(
    22.             'font'   => $configfile->paths->captcha->fonts . '/DejaVuSerif-Bold.ttf',
    23.             'imgDir' => $configfile->paths->captcha->img,
    24.             'imgUrl' => '../../data/img/captcha/',
    25.             'name'   => 'captcha',
    26.             'width'  => 150,
    27.             'height' => 80,
    28.             'fsize'  => 21,
    29.             'dotNoiseLevel' => 30,
    30.             'lineNoiseLevel'=> 3,
    31.             'timeout'   => 1000,
    32.             'wordlen'   => 5
    33.         ));
    34.        $captcha->generate();
    35.        $captcha_id = $captcha->getId();
    36.        $imgUrl = $captcha->getImgUrl();
    37.        $imgSuffix = $captcha->getSuffix();        
    38.            
    39.        $this->_helper->viewRenderer->setNoRender();
    40.        $this->view->captcha_id = $captcha_id;
    41.        $this->view->imgUrl = $imgUrl;
    42.        $this->view->imgSuffix = $imgSuffix;
    43.     }
    44. }
    45. ?>
    46.  
    нада втулить в контроллер так чтоб проверялись данные введеные в поле с каптчи.
    Ломал голову но так и не понял как. Тренеруюсь с книги Зерваса, там каптча генерировалась в PEAR, но мне этот подход непонравился, хочу использовать зендовскую каптчу, но как совместить все в кучу я незнаю :(
    Вот шаблон
    {include file='header.tpl'}

    <form method='post' action='../account/register'>
    <fieldset>
    <legend>Создать аккаунт</legend>
    <div class='error' {if !$form_processor->hasError()} style='display:none'{/if}>
    Произошла ошибка при заполнении формы, попробуйте заполнить заново
    </div>

    <div class='row' id='form_username_container'>
    <label for='form_username'>Имя пользователя</label>
    <input type='text' id='form_username' name='username' value='{$form_processor->username}'/>
    {include file='lib/error.tpl' error=$form_processor->getError('username')}
    </div>

    <div class='row' id='form_email_container'>
    <label for='form_email'>Адрес электронной почты</label>
    <input type='text' id='form_email' name='email' value='{$form_processor->email}'/>
    {include file='lib/error.tpl' error=$form_processor->getError('email')}
    </div>

    <div class='row' id='form_first_name_container'>
    <label for='form_first_name'>Фамилия</label>
    <input type='text' id='form_first_name' name='first_name' value='{$form_processor->first_name}'/>
    {include file='lib/error.tpl' error=$form_processor->getError('first_name')}
    </div>

    <div class='row' id='form_last_name_container'>
    <label for='form_last_name'>Отчество</label>
    <input type='text' id='form_last_name' name='last_name' value='{$form_processor->last_name}'/>
    {include file='lib/error.tpl' error=$form_processor->getError('last_name')}
    </div>

    <div class='captcha'>
    <img src='{$imgUrl}{$captcha_id}{$imgSuffix}'>
    </div>

    <div class='row' id='form_captcha_container'>
    <label for='form_captcha'> Введите выражение</label>
    <input type='text' id='form_captcha' name='captcha' value=''/>
    <input type='hidden' name='captcha_submit' value='{$captcha_id}'>
    {include file='lib/error.tpl' error=$form_processor->getError('captcha')}
    </div>

    <div>
    <input type='submit' value='register'/>
    </div>
    <div>
    <input type='reset'>
    </div>
    </fieldset>
    </form>

    {include file='footer.tpl'}

    Контроллер
    PHP:
    1.  
    2. class AccountController extends Mylib_GlobalControllerAction
    3. {    
    4.     public function registerAction()
    5.     {
    6.         $request = $this->getRequest();    
    7.        
    8.         $form_processor = new Mylib_FormProcessor_UserRegistration($this->db);
    9.  
    10.         if ($request->isPost())
    11.         {            
    12.             if ($form_processor->process($request))
    13.             {
    14.                 $session = new Zend_Session_Namespace('registration');
    15.                 $session->user_id = $form_processor->user->getId();
    16.                 $this->_redirect('/account/registercomplete');
    17.             }
    18.         }
    19.  
    20.         $this->view->form_processor = $form_processor;
    21.     }
    22.  
    23.     public function registercompleteAction()
    24.     {
    25.         $session = new Zend_Session_Namespace('registration');
    26.         $user = new Mylib_DatabaseObject_User($this->db);
    27.         if (!$user->load($session->user_id))
    28.         {
    29.             $this->_forward('register');
    30.             return;
    31.         }
    32.  
    33.         $this->view->user = $user;
    34.     }
    35.  
    36.     public function loginAction()
    37.     {
    38.        
    39.     }
    40. }
    41. ?>
    42.