Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php][Zend Framework] Problem z captchą
Forum PHP.pl > Forum > Przedszkole
sweter
Witam,
mam taki kod w klasie formularza do generowania captchy:
  1. $captcha = new Zend_Form_Element_Captcha('captcha',
  2. 'label' => "Przepisz ciąg liter:",
  3. 'captcha' => 'Figlet',
  4. 'captchaOptions' => array(
  5. 'captcha' => 'Figlet',
  6. 'wordLen' => 5,
  7. 'timeout' => 300,
  8. ),
  9. )
  10. );

Walidacja formularza wygląda następująco:
  1. $formularz_kontaktowy = new Contact;
  2. $postData = array();
  3. if($this->_request->isPost()){
  4. $postData = $this->_request->getPost();
  5. if($formularz_kontaktowy->isValid($postData)){
  6. $formData = $formularz_kontaktowy->getValues();
  7. Zend_Debug::dump($formData);
  8. }
  9. }

Na stronie pojawiają mi się 3 pola input odpowiedzialne za captche:
  1. <input type="hidden" name="captcha[id]" value="4cd8e7a863eeb8e015959145e88b8e89" captchaOptions="Figlet 5 300" id="captcha-id">
  2. <input type="text" name="captcha[input]" id="captcha-input" value="" captchaOptions="Figlet 5 300">
  3. <input type="text" name="captcha" id="captcha" value="4cd8e7a863eeb8e015959145e88b8e89" captchaOptions="Figlet 5 300">


Teraz mam trochę pytań smile.gif :
1. Jak mogę usunąć (i czy wogóle mogę?) input name="captcha"?
2. Czemu po wpisaniu dobrze znaków wywala mi błąd: "Captcha value is wrong"?
3. Czasami pojawia mi się taki symbol:
Kod
  ____      _____     _  _      ___      ______  
|  _ \\   |  ___||  | \| ||   / _ \\   /_____//
| |_| ||  | ||__    |  ' ||  | / \ ||  `____ `  
| .  //   | ||__    | .  ||  | \_/ ||  /___//  
|_|\_\\   |_____||  |_|\_||   \___//   `__ `    
`-` --`   `-----`   `-` -`    `---`    /_//    
                                        `-`

Co oznacza to ostatnie?
darko
Korzystaj z Zend_Service_ReCaptcha, zarejestruj się w usłudze recaptcha na https://admin.recaptcha.net/ (od kiedy google kupiło tę usługę aby się zarejesterować musisz posiadać aktywne konto poczty gmail), dodaj hosty/domeny, na których ma być aktywna usługa (można też zarejestrować localhost - w celach testowych). Następnie podaję Ci przykład użycia:

  1. class TwojFormularzLogowania extends Zend_Form
  2. {
  3. public function __construct($option = null)
  4. {
  5. parent::__construct($option);
  6.  
  7. $this->setName('login');
  8.  
  9. $user = new Zend_Form_Element_Text('user');
  10. $user->setLabel('Login:')
  11. ->setRequired(true)
  12. ->addErrorMessage("Proszę podać login")
  13. ->setAttrib('class','textfield');
  14.  
  15. $pass = new Zend_Form_Element_Password('pass');
  16. $pass->setLabel("Hasło:")
  17. ->setRequired(true)
  18. ->addErrorMessage("Proszę podać hasło")
  19. ->setAttrib('class','textfield');
  20.  
  21. $login = new Zend_Form_Element_Submit('login');
  22. $login->setLabel('Zaloguj');
  23. $login->setAttrib("id","submit")
  24. ->setAttrib('class','submit');
  25.  
  26. // recaptcha service
  27. $publicKey = "TU WPISZ SWÓJ WYGENEROWANY KLUCZ PUBLICZY";
  28. $privateKey = "A TU PRYWATNY";
  29.  
  30. $srvCaptcha = new Zend_Service_ReCaptcha($publicKey, $privateKey);
  31. $captcha = new Zend_Form_Element_Captcha("captcha",
  32. array('captcha' => 'ReCaptcha', 'captchaOptions' => array('captcha' => 'ReCaptcha', 'service' => $srvCaptcha)));
  33. $captcha->addErrorMessage('Proszę wpisać poprawny tekst z obrazka');
  34. //
  35. $this->addElements(array($user, $pass, $captcha, $login));
  36. $this->setMethod('post');
  37. $this->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/AKCJA_FORMULARZA');
  38.  
  39. }
  40. }

i voila! U mnie wszystko działa od dłuższego czasu bez żadnych problemów. Pzdr.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.