Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP]Jedno pole wyboru mniej
Forum PHP.pl > Forum > Przedszkole
-Bruksela-
Witam, musze usunąć jedno pole wyboru z formularza które jest obowiązkowe i nie można zakończyć rejestracji bez niego, chodzi o numer telefonu. Strona posiada bazę SQL zainstalowana na serwerze Superhost.pl. Zapis w html wygląda tak:

  1. td>*Nr telefonu:</td>
  2. <td><input name="phoneNumber" value="<?php echo $this->escape($this->phoneNumber); ?>" class="sinput3"/></td>
  3. </tr>


Samo usunięcie gwaiazdki nie pomaga smile.gif
patrysiek2
Gdzieś jest jakiś 'walidator' daj cały kod...
Gość
  1. <h1>Rejestracja</h1><hr/>
  2.  
  3. <?php if($this->showForm) { ?>
  4. Aby utworzyć konto w serwisie wypełnij poniższy formularz rejestracyjny, a następnie kliknij przycisk "Zarejestruj". Na Twój adres e-mail zostanie wysłana wiadomośc potwierdzająca chęć założenia konta. Wszystkie pola oznaczone (*) są wymagane.<br/><br/>
  5.  
  6. <?php
  7. if(!empty($this->errors)) {
  8. echo '<strong>Rejestracja nie powiodła się z powodu błędów: </strong><br/>';
  9. foreach($this->errors as $error)
  10. echo '<div class="message"><img src="public/images/error.gif"/> '.$this->escape($error).'</div>';
  11. echo '<br/>';
  12. }
  13. ?>
  14.  
  15. <table cellspacing="0" cellpadding="0">
  16. <form method="post" action="">
  17. <tr>
  18. <td style="width:130px;">*Login:</td>
  19. <td><input name="login" value="<?php echo $this->escape($this->login); ?>" class="sinput3"/></td>
  20. </tr>
  21. <tr>
  22. <td>*Hasło:</td>
  23. <td><input type="password" name="password" class="sinput3"/></td>
  24. </tr>
  25. <tr>
  26. <td>*Hasło (powtórz):</td>
  27. <td><input type="password" name="password2" class="sinput3"/></td>
  28. </tr>
  29.  
  30. <tr>
  31. <td>*Imię / nazwa agencji:</td>
  32. <td><input name="name" value="<?php echo $this->escape($this->name); ?>" class="sinput3"/></td>
  33. </tr>
  34. <tr>
  35. <td>Nazwisko:</td>
  36. <td><input name="surname" value="<?php echo $this->escape($this->surname); ?>" class="sinput3"/></td>
  37. </tr>
  38. <tr>
  39. <td>Ulica i nr:</td>
  40. <td><input name="street" value="<?php echo $this->escape($this->street); ?>" class="sinput3"/></td>
  41. </tr>
  42.  
  43. <tr>
  44. <td>Miasto:</td>
  45. <td><input name="city" value="<?php echo $this->escape($this->city); ?>" class="sinput3"/></td>
  46. </tr>
  47. <tr>
  48. <td>Kod pocztowy:</td>
  49. <td><input name="postCode" value="<?php echo $this->escape($this->postCode); ?>" class="sinput3"/></td>
  50. </tr>
  51. <tr>
  52. <td>Województwo:</td>
  53. <td>
  54. <select name="province" value="<?php echo $this->escape($this->province); ?>" class="sinput">
  55. <option selected="selected" value="">wybierz województwo</option>
  56. <?php
  57. foreach($this->provinces as $province)
  58. if($province->id == $this->escape($this->province))
  59. echo '<option selected="selected" value="'.$province->id.'">- '.$province->province.'</option>';
  60. else
  61. echo '<option value="'.$province->id.'">- '.$province->province.'</option>';
  62. ?>
  63. </select>
  64. </td>
  65. </tr>
  66. <tr>
  67. <td>Kraj:</td>
  68. <td>
  69. <select name="country" class="sinput">
  70. <option selected="selected" value="">wybierz kraj</option>
  71. <?php
  72. foreach($this->countries as $country)
  73. if($country->id == $this->escape($this->country))
  74. echo '<option selected="selected" value="'.$country->id.'">- '.$country->country.'</option>';
  75. else
  76. echo '<option value="'.$country->id.'">- '.$country->country.'</option>';
  77. ?>
  78. </select>
  79. </td>
  80. </tr>
  81. <tr>
  82. <td>*Nr telefonu:</td>
  83. <td><input name="phoneNumber" value="<?php echo $this->escape($this->phoneNumber); ?>" class="sinput3"/></td>
  84. </tr>
  85. <tr>
  86. <td>Nr tel. kom.:</td>
  87. <td><input name="mobileNumber" value="<?php echo $this->escape($this->mobileNumber); ?>" class="sinput3"/></td>
  88. </tr>
  89. <tr>
  90. <td>*E-mail:</td>
  91. <td><input name="email" value="<?php echo $this->escape($this->email); ?>" class="sinput3"/></td>
  92. </tr>
  93. <tr>
  94. <td>NIP:</td>
  95. <td><input name="nipNumber" value="<?php echo $this->escape($this->nipNumber); ?>" class="sinput3"/></td>
  96. </tr>
  97. <tr>
  98. <td></td>
  99. <td><input type="image" src="public/images/register.gif" id="submit" value="Zarejestruj" /></td>
  100. </tr>
  101. <tr>
  102. <td></td>
  103. <td>Wciśnięcie przycisku "Zarejestruj", a tym samym założenie konta oznacza akceptację <a href="pages/Regulamin.html">Regulaminu</a>.</td>
  104. </tr>
  105. </form>
  106.  
  107. <?php } else { ?>
  108. <img src="public/images/register_ok.jpg" alt="" class="ph"/><strong>Gratulacje!</strong><br> Proces rejestracji przebiegł pomyślnie, jednak Twoje konto nie jest jeszcze aktywne. Na adres e-mail który podałeś podczas rejestracji została wysłana wiadomość z linkiem aktywującym Twoje konto.
  109. <?php } ?>
IProSoft
Tutaj nie ma walidacji, musisz odnaleźć miejsce gdzie generowane jest $this->errors.
Możliwe, że będzie tam coś w deseń vlidate('mobileNumber') - wystarczy usunąć.
-Bruksela-
W 6 lini mamy ten zapis podejrzewam że problem jest uregulowany w SQL.
IProSoft
W 6, a w sumie 7 masz sprawdzanie zmiennej zawierającej błedy więc gdzieś musi być validacja, napewno nie w bazie tylko w pliku.
Choć z bazą też później może być problem bo będzie wołać o numer, możesz zrobić tak:
Kod
<input name="phoneNumber" value="12345 lub jakiś domyslny numer" type="hidden" />

ale najlepszym rozwiązaniem było by odnalezienie odpowiedniego kodu.


-Bruksela-
Znalazłem coś takiego:

  1. if($this->_request->isPost()) {
  2.  
  3. foreach($this->_request->getPost() as $name => $value)
  4. $form[$name] = $value;
  5.  
  6. switch($this->_request->getPost('formType')) { // case sent form
  7.  
  8. case 'data': // change account data settings
  9. if(empty($form['name']))
  10. $errors[] = 'Nie podałeś imienia / nazwy agencji.';
  11. if(empty($form['phoneNumber']))
  12. $errors[] = 'Nie podałeś numeru telefonu.';
  13. if(empty($errors)) { // update database recorde when all data is ok
  14. $usersData = new UsersDataTable();
  15. $userData = array(
  16. 'name' => $form['name'],
  17. 'surname' => $form['surname'],
  18. 'street' => $form['street'],
  19. 'city' => $form['city'],
  20. 'province' => intval($form['province']),
  21. 'country' => intval($form['country']),
  22. 'postCode' => $form['postCode'],
  23. 'phoneNumber' => $form['phoneNumber'],
  24. 'mobileNumber' => $form['mobileNumber'],
  25. 'nipNumber' => $form['nipNumber']
  26. );
  27. $usersData->update($userData, 'userId = '.Zend_Auth::getInstance()->getIdentity()->id);
  28. }
  29. break;
  30.  


  1. // validate post data
  2. $validator = new Zend_Validate();
  3. $validator->addValidator(new Zend_Validate_StringLength(5, 25)) // login validator
  4. ->addValidator(new Zend_Validate_Alnum())
  5. ->addValidator(new Zend_Validate_NotEmpty());
  6.  
  7. if(!$validator->isValid($form['login']))
  8. $errors[] = 'Login musi zawierać od 5 do 25 znaków. Dozwolone są znaki alfabetyczne oraz cyfry.';
  9. else { // checking if account with this login not exist in database
  10. $users = new UsersTable;
  11. $select = $users->select();
  12. $select->from($users, 'count(id) as count')
  13. ->where('login = ?', $form['login']);
  14. $row = $users->fetchRow($select);
  15. if($row->count > 0)
  16. $errors[] = 'Niestety, ale podany login jest już zajęty. Spróbuj wybrać inny.';
  17. }
  18.  
  19. if(empty($form['password']) || empty($form['password2']))
  20. $errors[] = 'Nie podałeś hasła. Oba hasła muszą być takie same.';
  21. if($form['password'] != $form['password2'])
  22. $errors[] = 'Podane hasła nie są takie same.';
  23. if(empty($form['name']))
  24. $errors[] = 'Nie podałeś imienia / nazwy agencji.';
  25. if(empty($form['phoneNumber']))
  26. $errors[] = 'Nie podałeś numeru telefonu.';
  27. if(!Zend_Validate::is($form['email'], 'EmailAddress') || empty($form['email']))
  28. $errors[] = 'Nie podałeś adresu e-mail lub jest on nieprawidłowy.';
  29. else { // checking if account with this email not exist in database
  30. $users = new UsersDataTable;
  31. $select = $users->select();
  32. $select->from($users, 'count(id) as count')
  33. ->where('email = ?', $form['email']);
  34. $row = $users->fetchRow($select);
  35. if($row->count > 0)
  36. $errors[] = 'Niestety, ale podany e-mail występuje już w naszej bazie. Musisz podać inny adres e-mail.';
  37. }
  38.  
  39. if(empty($errors)) { // if form is ok, and havent any errors then add user to database and send verify email
  40. $this->view->showForm = 0;
  41. $password = sha1($form['password']);
  42. $users = new UsersTable;
  43. $users->insert(array('login' => $form['login'], 'password' => $password, 'active' => 0));
  44.  
  45. $db = Zend_Registry::get('db');
  46. $userId = $db->lastInsertId();
  47. $userData = array(
  48. 'userId' => $userId,
  49. 'name' => $form['name'],
  50. 'surname' => $form['surname'],
  51. 'street' => $form['street'],
  52. 'city' => $form['city'],
  53. 'province' => intval($form['province']),
  54. 'country' => intval($form['country']),
  55. 'postCode' => $form['postCode'],
  56. 'phoneNumber' => $form['phoneNumber'],
  57. 'mobileNumber' => $form['mobileNumber'],
  58. 'email' => $form['email'],
  59. 'nipNumber' => $form['nipNumber']
  60. );
  61. $usersData = new UsersDataTable;
  62. $usersData->insert($userData);
  63.  
  64. // verify code
  65. $code = sha1(time().$form['login']);
  66. $verifyCodes = new VerifyCodesTable;
  67. $verifyCodes->insert(array('userId' => $userId, 'code' => $code));
  68.  
  69. // verify email
  70. $settingsTable = new SettingsTable;
  71. $row = $settingsTable->fetchRow("title = 'verifyEmail'");
  72. $verifyEmail = nl2br($row->value);
  73. $verifyEmail = str_replace('{name}', $form['name'], $verifyEmail);
  74. $verifyEmail = str_replace('{serviceUrl}', $this->view->baseHref, $verifyEmail);
  75. $verifyEmail = str_replace('{verifyLink}', $this->view->baseHref.'account/verify/'.$code, $verifyEmail);
  76.  
  77. $row = $settingsTable->fetchRow("title = 'adminEmail'");
  78. $adminEmail = $row->value;
  79.  
  80. $mail = new Zend_Mail('utf-8');
  81. $mail->setBodyHtml($verifyEmail)
  82. ->setFrom($adminEmail, 'Administrator')
  83. ->addTo($form['email'], 'Użytkownik')
  84. ->setSubject('Weryfikacja konta - '.$this->view->baseHref)
  85. ->send();
  86. }
  87. $this->view->errors = $errors;
  88. }
  89.  
  90. if($this->view->showForm === NULL) // if showForm is not set then show form
  91. $this->view->showForm = 1;
  92.  
  93. if($this->view->showForm) { // show form but data is failed or empty
  94. // fetch countries rows from database
  95. $countries = new CountriesTable();
  96. $this->view->countries = $countries->fetchAll();
  97. }
  98. }


CAŁY PLIK TUTAJ
Gość
Udało się usunołem dwa razy twierdzenie w tym dokumencie:

  1. if(empty($form['phoneNumber']))
  2. $errors[] = 'Nie podałeś numeru telefonu.';


irmidjusz
co za masakra, jak widzę taki kod to mnie krew zalewa...
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.