Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Walidacja formularza (funkcje)
peja1990
post
Post #1





Grupa: Zarejestrowani
Postów: 150
Pomógł: 1
Dołączył: 4.12.2010

Ostrzeżenie: (10%)
X----


  1. $error = array();
  2. global $error;
  3.  
  4. function validateNames($value) {
  5. if(!ereg("^[A-ZŁŚ]{1}[a-ząęółśżźćń]{1,30} [A-ZŁŚ]{1}[a-ząęółśżźćń]{1,30}$", $value) && strlen($value) < 3)
  6. return $error[] = 1;
  7. }
  8.  
  9. function validateEmail($value) {
  10. if(filter_var($value, FILTER_VALIDATE_EMAIL) === FALSE && strlen($value) == 0)
  11. return $error[] = 1;
  12. }
  13.  
  14. function validateSubject($value) {
  15. if(empty($value))
  16. return $error[] = 1;
  17. }
  18.  
  19. function validateContent($value, $min) {
  20. if(empty($min)) $min = 10;
  21. if(strlen($value) < $min)
  22. return $error[] = 1;
  23. }
  24.  
  25. function validateCaptcha($code, $security) {
  26. if(strtolower($code) != strtolower($security))
  27. return $error[] = 1;
  28. }
  29.  
  30. echo validateSubject('');
  31. echo validateContent('', '');
  32. echo '>>>'.sizeof($error).'<<<'; // Tutaj chcę mieć ilość errorów, ale ciągle jest zero :(


Co tutaj więcej pisać ?! ... (IMG:style_emoticons/default/sad.gif)

Do każdej funkcji dodałem globalną zmienną $error i działa (IMG:style_emoticons/default/wink.gif)

Ten post edytował peja1990 4.05.2012, 19:45:56
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 15.09.2025 - 09:59