Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php]Walidacja formularza - Kod działa, ale czy jest poprawny?, Potrzebuję rady
--Andrzej--
post
Post #1





Goście







Cześć,

Napisałem sobie drobny skrypt walidacji formularza. System oczywiście działa, wszystko ładnie, tylko mam pytanie. Robię to w ten sposób:
  1. <?php
  2. // Check if the passwords match
  3.  if ($_POST['password'] != $_POST['confirmpass'])
  4.  {
  5.  
  6. $reg_error = 'Your passwords do not match';
  7. include 'templates/head.tpl';
  8. include 'templates/top.tpl';
  9. include 'templates/register.tpl';
  10. include 'templates/left.tpl';
  11. include 'templates/footer.tpl';
  12.  }
  13.  
  14.  if (!check_password_and_username($password))
  15.  {
  16.  
  17. $reg_error = 'Your passwords and login could not be the same';
  18. include 'templates/head.tpl';
  19. include 'templates/top.tpl';
  20. include 'templates/register.tpl';
  21. include 'templates/left.tpl';
  22. include 'templates/footer.tpl';
  23.  }
  24.  
  25.  if (!validSecurity($security))
  26.  {
  27.  // Reshow the form with an error
  28. $reg_error = 'You provided wrong security answer';
  29. include 'templates/head.tpl';
  30. include 'templates/top.tpl';
  31. include 'templates/register.tpl';
  32. include 'templates/left.tpl';
  33. include 'templates/footer.tpl';
  34.  }
  35.  
  36.  $username = $_POST['username'];
  37. if (!check_username($username))
  38. {
  39. // Reshow the form with an error
  40. $reg_error = 'Requested username is aldready in use';
  41. include 'templates/head.tpl';
  42. include 'templates/top.tpl';
  43. include 'templates/register.tpl';
  44. include 'templates/left.tpl';
  45. include 'templates/footer.tpl';
  46. }
  47.  
  48. $email = $_POST['email'];
  49. if (!check_email($email))
  50. {
  51. // Reshow the form with an error
  52. $reg_error = 'Requested e-mail address is aldready in use';
  53. include 'templates/head.tpl';
  54. include 'templates/top.tpl';
  55. include 'templates/register.tpl';
  56. include 'templates/left.tpl';
  57. include 'templates/footer.tpl';
  58. }
  59. ?>


To tylko fragment kodu. Teraz kolej na pytanie: Czy ten kod jest napisany poprawnie?smile.gif To znaczy, czy funkcje są stosowane tak jak manual przykazał? Nie potrzebuję żadnego gotowca, tylko paru rad jak ewentualnie poprawić, zmienić. Formularz ma 11 pół, a kod walidacji zajmuje ponad 150 linijek. Dlatego własnie pytam.

Teraz pytanie poboczne. Czy muszę w każdym pliku serwisu include'ować plik init.php /łączenie z bazą/ czy tylko w tych, które tego wymagają. Register_globals mam wyłączone. Całe logowania odbywa się na sesjach, więc na chłopski rozum biorąc, nie potrzeba, ale chciałbym poznać opinie specjalistów.

Pozdrawiam
A.
Powód edycji: dodanie tagu ~Cienki1980
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 20.08.2025 - 22:44