Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> PEAR::QuicForm i kilka formularzy, co zrobic zeby sie nie gryzly ze soba
squid
post 6.07.2005, 14:59:42
Post #1





Grupa: Zarejestrowani
Postów: 358
Pomógł: 0
Dołączył: 3.07.2003
Skąd: Szczecin->niebuszewo->*(next to window)

Ostrzeżenie: (0%)
-----


Mam nastepujacy problem, na stornie jest kilka roznych formularzy tylu szukanie logowanie i jeszcze jakis tam, do stworzenia tych formularzy uzywam PEAR::QuicForm
oto przykladowy kod takiego formularza:
  1. <?
  2. $action = 'index.php?model=users&action=register';
  3.  
  4. $regions = array (
  5. 'Dolnośląskie',
  6. 'Kujawsko-pomorskie',
  7. 'Lubelskie Lubuskie',
  8. 'Łódzkie',
  9. 'Małopolskie',
  10. 'Mazowieckie',
  11. 'Opolskie',
  12. 'Podkarpackie',
  13. 'Podlaskie',
  14. 'Pomorskie',
  15. 'Śląskie',
  16. 'Świętokrzyskie',
  17. 'Warmińsko-Mazurskie',
  18. 'Wielkopolskie',
  19. 'Zachodniopomorskie'
  20. );
  21.  
  22. $form = new HTML_QuickForm($formName, $method, $action);
  23.  
  24. $form->addElement('header', '', $label);
  25. $form->addElement('text', 'newUserLogin', 'Login');
  26. $form->addElement('password', 'pass1', 'Hasło');
  27. $form->addElement('password', 'pass2', 'Powtórz hasło');
  28. $form->addElement('text', 'firm', 'Firma');
  29. $form->addElement('text', 'nip', 'NIP');
  30. $form->addElement('text', 'fname', 'Imie');
  31. $form->addElement('text', 'lname', 'Nazwisko');
  32. $form->addElement('text', 'street', 'Ulica');
  33. $form->addElement('text', 'zipCode', 'Kod pocztowy');
  34. $form->addElement('text', 'city', 'Miejscowość');
  35. $form->addElement('select', 'region', 'Województwo', $regions);
  36. $form->addElement('text', 'email', 'E-mail');
  37. $form->addElement('text', 'tel', 'Telefon');
  38. $form->addElement('text', 'gsm', 'Telefon kom.');
  39. $form->addElement('submit', '', 'Potwierdzam');
  40.  
  41. $form->addRule('newUserLogin', 'To pole musi byc wypełnione!', 'required');
  42. $form->addRule('pass1', 'To pole musi byc wypełnione!', 'required');
  43. $form->addRule('pass2', 'To pole musi byc wypełnione!', 'required');
  44. $form->addRule('fname', 'To pole musi byc wypełnione!', 'required');
  45. $form->addRule('lname', 'To pole musi byc wypełnione!', 'required');
  46. $form->addRule('street', 'To pole musi byc wypełnione!', 'required');
  47. $form->addRule('zipCode', 'To pole musi byc wypełnione!', 'required');
  48. $form->addRule('city', 'To pole musi byc wypełnione!', 'required');
  49. $form->addRule('region', 'To pole musi byc wypełnione!', 'required');
  50. $form->addRule('email', 'To pole musi byc wypełnione!', 'required');
  51. $form->addRule('tel', 'To pole musi byc wypełnione!', 'required');
  52. $form->addRule('gsm', 'To pole musi byc wypełnione!', 'required');
  53.  
  54. $form->addRule('newUserLogin', 'Nieprawidłowe znaki!',
  55. 'regex', '/^[a-zA-Z0-9_]{1,}$/'
  56. );
  57. $form->addRule('newUserLogin', 'Nieprawidłowa liczba znaków!', 'rangelength',
  58. array(5,15)
  59. );
  60. $form->addRule('pass1', 'To pole może zawierać tylko litery i cyfry!',
  61. 'alphanumeric'
  62. );
  63. $form->addRule('pass1', 'Nieprawidłowa liczba znaków!', 'rangelength',
  64. array(6,64)
  65. );
  66. // compare the passwords
  67. $form->addRule(array('pass1', 'pass2'), 'Poda hasła nie są identyczne!',
  68. 'compare');
  69.  
  70. $form->addRule('firm',
  71. 'To pole może zawierac tylko litery alfabetu, cyfry o spacje!',
  72. 'regex', '/^[a-zA-Z0-9ąˇćĆęńŃłŁśŚĽŹżŻóÓ ]{1,}$/'
  73. );
  74. $form->addRule('nip', 'Niepradidłowy numer', 'regex', '/^[0-9-]{1,}$/');
  75. $form->addRule('fname', 'To pole może zawierać tylko znaki alfabetu!',
  76. 'regex', '/^[a-zA-ZąˇćĆęńŃłŁśŚĽŹżŻóÓ ]{1,}$/'
  77. );
  78. $form->addRule('lname', 'To pole może zawierać tylko znaki alfabetu!',
  79. 'regex', '/^[a-zA-ZąˇćĆęńŃłŁśŚĽŹżŻóÓ -]{1,}$/'
  80. );
  81. $form->addRule('street',
  82. 'Nieprawidłowy adres!',
  83. 'regex', '/^[a-zA-Z0-9ąˇćĆęńŃłŁśŚĽŹżŻóÓ'/ ,.]{1,}$/'
  84. );
  85. $form->addRule('zipCode',
  86. 'Nieprawidłowy kod!',
  87. 'regex', '/^[0-9]{2}-[0-9]{3}$/'
  88. );
  89. $form->addRule('city',
  90. 'Nieprawidłowa nazwa!',
  91. 'regex', '/^[a-zA-Z0-9ąˇćĆęńŃłŁśŚĽŹżŻóÓ' -]{1,}$/'
  92. );
  93. $form->addRule('email', 'Nieprawidłowy adres!', 'email');
  94. $form->addRule('tel',
  95. 'Nieprawidłowy numer!',
  96. 'regex', '/^[0-9-() ]{1,}$/'
  97. );
  98. $form->addRule('gsm',
  99. 'Nieprawidłowy numer!',
  100. 'regex', '/^[0-9-() ]{1,}$/'
  101. );
  102. $form->setRequiredNote
  103. ('<font color=\"red\" size=\"1\">*</font>To pole jest wymagane');
  104.  
  105. // try to validate the form
  106. if ( $form->validate() )
  107. {
  108. $data = array(
  109. $form->exportValue('newUserLogin'),
  110. $form->exportValue('pass1'),
  111. $form->exportValue('firm'),
  112. $form->exportValue('nip'),
  113. $form->exportValue('fname'),
  114. $form->exportValue('lname'),
  115. $form->exportValue('street'),
  116. $form->exportValue('zipCode'),
  117. $form->exportValue('city'),
  118. $regions [ $form->exportValue('region') ],
  119. $form->exportValue('email'),
  120. $form->exportValue('tel'),
  121. $form->exportValue('gsm')
  122. );
  123.  
  124. if ( $result = users::add ( $data ) )
  125. {
  126. $this->tpl->assign('message', $result);
  127. }
  128. else
  129. {
  130. $this->tpl->assign('error', 'Błąd podczas dodawania');
  131. }
  132. }
  133. else
  134. {
  135. $renderer =& new HTML_QuickForm_Renderer_Array(true, true);
  136. $form->accept($renderer);
  137. $this->tpl->assign($formName, $renderer->toArray());
  138. }
  139.  
  140. ?>


problem w tym ze jesli klikne "OK" w dowolnym formularzu wszystkie probuja sie "wyslac". Macie pomysl jak temu zaradzic?

Ten post edytował squid 6.07.2005, 15:28:29


--------------------
Jeśli życie to kara to nieźle nabroiłem ;-)
Go to the top of the page
+Quote Post
bieniek
post 6.07.2005, 19:42:57
Post #2





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 6.07.2005

Ostrzeżenie: (0%)
-----


Przeczytaj to, a także changelog:
QuickForm bug


--------------------
Go to the top of the page
+Quote Post
squid
post 6.07.2005, 20:15:53
Post #3





Grupa: Zarejestrowani
Postów: 358
Pomógł: 0
Dołączył: 3.07.2003
Skąd: Szczecin->niebuszewo->*(next to window)

Ostrzeżenie: (0%)
-----


Cytat(bieniek @ 2005-07-06 20:42:57)
Przeczytaj to, a także changelog:
QuickForm bug

Dzieki wielkie biggrin.gif

wieki by mi zajelo zanim bym do tego doszedl smile.gif

wystarczylo ze zmienilem konstruktor kazdego formularza
z:
  1. <?php
  2. $form = new HTML_QuickForm($formName, $method, $action);
  3. ?>

na

  1. <?php
  2. $form = new HTML_QuickForm($formName, $method, $action, null, null, true);
  3. ?>


6-ty argument konstruktora oddany w wersji 3.2 i ustawiony na true dodaje do kazdego formularza specjanle pole dzieki ktoremu QuickForm orientuje sie czy to ten wlasnie formularz zostal wypelniony smile.gif

Jeszcze raz BIG THNX!!!


--------------------
Jeśli życie to kara to nieźle nabroiłem ;-)
Go to the top of the page
+Quote Post
bieniek
post 7.07.2005, 08:03:32
Post #4





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 6.07.2005

Ostrzeżenie: (0%)
-----


Nie ma sprawy cool.gif


--------------------
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 13.08.2025 - 22:34