Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][Zend]Walidiacja formularzy
Forum PHP.pl > Forum > Przedszkole
sweter
Witam,
mam taki formularz:
  1. $email_zwrotny = new Zend_Form_Element_Text('email_zwrotny');
  2. $sprawa = new Zend_Form_Element_Select('sprawa');
  3. $tresc = new Zend_Form_Element_Textarea('tresc');
  4.  
  5. $captcha = new Zend_Form_Element_Captcha(
  6. 'captcha', // This is the name of the input field
  7. array('label' => 'Write the chars to the field',
  8. 'captcha' => array( // Here comes the magic...
  9. // First the type...
  10. 'captcha' => 'Image',
  11. // Length of the word...
  12. 'wordLen' => 6,
  13. // Captcha timeout, 5 mins
  14. 'timeout' => 300,
  15. // What font to use...
  16. 'font' => './public/fonts/MS_Reference_Sans Serif.ttf',
  17. // Where to put the image
  18. 'imgDir' => './public/images/captcha/',
  19. // URL to the images
  20. // This was bogus, here's how it should be... Sorry again :S
  21. 'imgUrl' => 'http://127.0.0.1/treetime4/public/images/captcha/',
  22. )));
  23. $submit = new Zend_Form_Element_Submit('submit', array('class'=>'middle'));
  24.  
  25.  
  26.  
  27. $email_zwrotny ->setLabel('E-mail zwrotny:') // etykieta
  28. ->addFilter(new Zend_Filter_StripTags()) // filtruj funkcją StripTags()
  29. ->addFilter(new Zend_Filter_StringTrim()); // filtruj funkcją StringTrim()
  30. $sprawa ->setLabel('Temat *:') // etykieta
  31. ->setRequired(true) // pole jest wymagane
  32. ->addMultiOption(null, null)
  33. ->addValidator(new Zend_Validate_NotEmpty(), true)
  34. ->addMultiOptions(array(1=>'Reklama', 2=>'Znalazłem/łam błąd na stronie', 3=>'Sprawy techniczne', 4=>'Nowe pomysły', 5=>'Inne'));
  35. $tresc ->setLabel('Treść *:') // etykieta
  36. ->setRequired(true) // pole jest wymagane
  37. ->addValidator(new Zend_Validate_NotEmpty(), true) // to pole nie może być puste
  38. ->addFilter(new Zend_Filter_StripTags()) // filtruj funkcją StripTags()
  39. ->addFilter(new Zend_Filter_StringTrim()); // filtruj funkcją StringTrim()
  40. $captcha ->setLabel('Przepisz kod z obrazka *:')
  41. ->setRequired(true) // pole jest wymagane
  42. ->addValidator(new Zend_Validate_NotEmpty(), true); // to pole nie może być puste
  43. //->addFilter(new Zend_Filter_StripTags()) // filtruj funkcją StripTags()
  44. //->addFilter(new Zend_Filter_StringTrim()); // filtruj funkcją StringTrim()
  45. $submit ->setLabel('Wyślij wiadomość');

a tak wygląda kontroler:
  1. $form = new Contact();
  2.  
  3. $formData = array();
  4. if($this->_request->isPost()){
  5. $postData = $this->_request->getPost();
  6. if($form->isValid($postData)){
  7. $formData = $form->getValues();
  8. Zend_Debug::dump($formData);
  9. // forumlarz wypełniony poprawnie
  10.  
  11. }
  12. echo "<pre>";
  13. print_r($formData);
  14. echo "</pre>";
  15.  
  16. }
  17.  
  18.  
  19. $this->view->form = $form;

No i teraz pytanie: dlaczego poprawnie sprawdza mi wszystkie pola poza Captchą? Zawsze pojawia się "Captcha value is wrong" sad.gif
Poradźcie coś...
Pilsener
1. Dawaj takie tematy w PHP->frameworki
2. Nie wiem co Ci nie działa, ja robię tak:
  1. //form
  2. $captcha = new Zend_Form_Element_Captcha('captcha',
  3. 'label' => "Please verify you're a human",
  4. 'captcha' => array(
  5. 'captcha' => 'Figlet',
  6. 'wordLen' => 6,
  7. 'timeout' => 300,
  8. ),
  9. ));
  10. $this->addElement($captcha);
  11. //controller
  12. if($request->isPost() && $form->isValid($request->getParams()){
  13. //i tu mi wszystko działa, jeśli poprawnie wpisze captcha
  14. }
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.