login  Naam:   Wachtwoord: 
Registreer je!
 Forum

[Php] error weergeven

Offline stenno - 18/10/2005 12:19 (laatste wijziging 18/10/2005 16:10)
Avatar van stennoPHP interesse Ik heb een formulier met een submit knop.
als ik op de submitknop druk heb ik een script nodig dat controleerd of alle velden zijn ingevuld. Zoja moet hij het formulier versturen zo neej moet naast het veld dat niet ingevuld is een error komen.

Weet iemand hoe ik dit moet doen ??

6 antwoorden

Gesponsorde links
Offline Thomas - 18/10/2005 12:52 (laatste wijziging 18/10/2005 13:04)
Avatar van Thomas Moderator
  1. <?php
  2. $error_name = "";
  3. $error_pass = "";
  4. if(isset($_POST['action'])) {
  5. // formulier gesubmit - controleer invoer
  6. // als deze niet klopt, geef $error_name of $error_pass een waarde
  7. // als alles klopt, stuur iemand door met header() ofzo
  8. }
  9. ?>
  10. <form action="..." method="post">
  11. <input type="text" name="name" /> <?= $error_name ?><br />
  12. <input type="password" name="pass" /> <?= $error_pass ?><br />
  13. <input type="hidden" name="action" value="login" />
  14. </form>


Al is het niet verstandig om informatie te geven over wat er aan logins / wachtwoorden niet klopt, want dit zou kwaadwillenden informatie kunnen geven over wat voor gegevens ze zouden moeten invullen om in te kunnen loggen.
Offline stenno - 18/10/2005 13:05 (laatste wijziging 18/10/2005 16:22)
Avatar van stenno PHP interesse bedankt maar ik weet nog steeds niet hoe het moet.

Edit ik word hier echt hevig depressief van !!

dus ik ga maar ff een heel script posten.

dit is mijn script:

  1. <html>
  2. <head>
  3. <title>Mijn eerste php script</title>
  4. <script language="JavaScript" type="text/javascript">
  5. <!--
  6. function check()
  7. {
  8. if ((document.form3.usernamecheck.checked == true)&&(document.form3.nameiscorrect2.checked == true)&&(document.form3.agree.checked == true))
  9. {
  10. document.form3.verzenden.disabled = false;
  11. } else
  12. {
  13. document.form3.verzenden.disabled = true;
  14. }
  15. }
  16. -->
  17. </script>
  18. </head>
  19. <body>
  20. <?php
  21. if (isset($_POST['verzenden'])){
  22. if(empty($username)) {
  23. ?>
  24. <script>document.getElementById('spanuser').display='block';</script>
  25. <?php
  26. ;}
  27. if(empty($email)) {
  28. ?>
  29. <script>document.getElementById('spanemail').display='block';</script>
  30. <?php
  31. ;}
  32. if(empty($userlink)) {
  33. ?>
  34. <script>document.getElementById('spanlink').display='block';</script>
  35. <?php
  36. ;}
  37. if(empty($armysize)) {
  38. ?>
  39. <script>document.getElementById('spanarmy').display='block';</script>
  40. <?php
  41. ;}
  42. if($_POST['alliance'] == 0)
  43. {
  44. ?>
  45. <script>document.getElementById('spanalliance').display='block';</script>
  46. <?php
  47. ;}
  48. else
  49. {
  50. ?>
  51. You are succesfully signed up.
  52. <?php
  53. ;}
  54. ;}else{
  55. ?>
  56. <form name="form3" method="post" action="">
  57. <center>
  58. <div style="border-collapse:collapse;border:1px solid;width:750px">
  59. <center>
  60. <table border="0" bordercolor="" style="border-collapse:collapse;" width="100%">
  61. <tr>
  62. <th height="30" bgcolor="darkblue" align="center" colspan="3"><font size="5">Registrations Profile</font></th>
  63. </tr>
  64.  
  65. <tr>
  66. <td colspan="3" bgcolor="blue"><font color="">&nbsp;&nbsp;&nbsp;Vitals - pay careful attention to what you enter, it's hard to log in if you mess any of it up</font></td>
  67. </tr>
  68.  
  69. <tr>
  70. <td width="20%" valign="bottom">Username:</td>
  71. <td><font size="2"> This is required to be exactly the same as your Kings of Chaos username; the system will not work with any other name. Watch out for capitalization. (To be sure you get the right name, simply go to Command Center in Kings of Chaos, highlight your name at the top right corner of the User Info table, and paste it here.)<font></td>
  72. </tr>
  73.  
  74. <tr>
  75. <td valign="top"><input type="textinput" name="username" size="20" value=""/></td>
  76. <td><span id="spanuser" style="display:none"><font color="red">No valid Username!</font></span><input type="checkbox" name="usernamecheck" onclick="javascript:check();"/>OK, I checked my username at Kings of Chaos and put it in the box correctly. <b>(MUST be checked)</b></td>
  77. </tr>
  78.  
  79. <tr>
  80. <td width="20%" valign="bottom">Email address:</td>
  81. </tr>
  82.  
  83. <tr>
  84. <td valign="top"><input type="textinput" name="email" size="20" value=""/>&nbsp;&nbsp;</td>
  85. <td><span id="spanemail"style="display:none"><font color="red">No valid Emailaddress!</font></span><font color="red"> If you use a free webmail service such as Yahoo! or Hotmail, it is highly likely that your password will disappear into their spam filters. Please make sure that you NOTE DOWN YOUR PASSWORD when it appears on this site in a moment.</font></td>
  86. </tr>
  87.  
  88. <tr>
  89. <td width="20%" valign="bottom">Kings of Chaos Link:</td>
  90. </tr>
  91.  
  92. <tr>
  93. <td colspan="2"><input type="textinput" name="userlink" size="50" value=""/>&nbsp;&nbsp;<span id="spanlink" style="display:none"><font color="red">No valid Uniquelink!</font></span>
  94. </td>
  95. </tr>
  96.  
  97. <tr>
  98. <td colspan="2" height="40"></td>
  99. </tr>
  100.  
  101. <tr>
  102. <td colspan="2" height="30"></td>
  103. </tr>
  104.  
  105. <tr>
  106. <td width="20%" valign="bottom">Current Army Size:</td>
  107. </tr>
  108.  
  109. <tr>
  110. <td width="20%" valign="bottom"><input type="textinput" name="armysize" size="5" />
  111. <select name="race">
  112. <option value="Humans">Humans</option>
  113. <option value="Dwarves">Dwarves</option>
  114. <option value="Elves">Elves</option>
  115. <option value="Orcs">Orcs</option>
  116. </select>
  117. &nbsp;&nbsp;<span id="spanamry"style="display:none"><font color="red">No valid Armysize!</font></span>
  118. </td>
  119. </tr>
  120.  
  121. <tr>
  122. <td colspan="2" height="10"></td>
  123. </tr>
  124.  
  125. <tr bgcolor="darkblue">
  126. <td colspan="2" height="30"><font size="5"><b>Alliance</b></font></td>
  127. </tr>
  128.  
  129. <tr>
  130. <td>
  131. <select name="alliance">
  132. <option value="0" selected="selected" >Select an alliance from the list</option>
  133. <option value="1" >LOG member</option>
  134. <option value="2" >Lordclicker User</option>
  135. </select>
  136. </td>
  137. <td>&nbsp;Please select 'Lordclicker User', unless you are a member of Lords of Gondor.&nbsp;<span id="spanalliance" style="display:none"><font color="red">Please select an alliance!</font></span><br /><input type="checkbox" onclick="javascript:check();" name="nameiscorrect2"/>I have selected an appropriate alliance <b>(MUST be checked)</b></td>
  138. </tr>
  139.  
  140. <tr bgcolor="darkblue">
  141. <td colspan="2" height="30"><font size="5"><b>Agreement</b></font></td>
  142. </tr>
  143.  
  144. <tr>
  145. <td colspan="2">
  146. You need to have checked all three check boxes in this form.<br /><br />
  147. Checking this one signifies one of the following two: <ol><li>that you are a member of Lords of Gondor or are in its command chain, and as such, you will not attack or attempt to recruit as an officer ANYONE in Lords of Gondor or its command chain, and that you will uphold the high standards of gameplay and citizenship that have come to be the trademarks of Lords of Gondor; that you will not break Kings of Chaos rules, spam or harass people in the game or out; that you understand you must most definitely kick ass in the game. (That's what we're all about)<br /><br /><b>or</b><br/><br/></li><li>that you agree that you are NOT in an alliance which is an enemy of Lords of Gondor</li></ol>
  148. <input type="checkbox" name="agree" onclick="javascript:check();"/> I agree to one of the two above statements. <b>(MUST be checked)</b>
  149. </td>
  150. </tr>
  151.  
  152. <tr>
  153. <td colspan="2" height="10"></td>
  154. </tr>
  155.  
  156. <tr>
  157. <td colspan="2" align="center"><input type="submit" name="verzenden" value="Sign up" disabled/></td>
  158. </tr>
  159.  
  160. <tr>
  161. <td colspan="2" height="10"></td>
  162. </tr>
  163.  
  164. </table>
  165. </center>
  166. </div>
  167. <br />
  168. </center>
  169. </form>
  170. <?php
  171. ;}
  172. ?>
  173. </body>
  174. </html>


Het enige dat ik wil is al er op de submit gedrukt is moet er gecontroleerd word of alles is ingevuld zo niet (bijv username is niet ingevuld) dan moet het formulier niet verzonden worden en moet achter het inputveld voor username de error weergegeven worden.

Als wel alles is ingevuld moet er in beeld komen: "You are succesfully signed up."

Weet iemand hoe ik dit doe??
Offline Ultimatum - 18/10/2005 14:20
Avatar van Ultimatum PHP expert weet niet hoe je het in je formulier zet maar het is iets van

  1. if(empty($veldnaam)) {
  2. echo "je kan het niet leeglaten";
  3. }elseif{
  4. (empty($veldnaam2)){

etc.. in die trant d8 ik 
Offline stenno - 18/10/2005 15:05 (laatste wijziging 18/10/2005 16:38)
Avatar van stenno PHP interesse Ik wilde dit maken door een <span>'s naast de inputvelden te maken vervolgens die op style="display:none" te zetten. En de spans weer te geven wanneer het inputveld ervoor leeg was.

Maar dan verzend hij het form als nog natuurlijk.
Ik dacht dat je het verzenden wel stop kon zetten met exit; ofzoiets dergelijks. maar ook dat blijkt niet te kunnen
Offline Maarten - 18/10/2005 20:12
Avatar van Maarten Erelid Dat kan wel, maar dan moet dat niet boven je form staan maar eronder. Want nu zijn de elementen nog niet aangemaakt en wil je hun display al aanpassen.. onder je form zijn de elementen al aangemaakt (daar deze tussen je form staan).
Offline stenno - 18/10/2005 20:31
Avatar van stenno PHP interesse Okeej code verandert maar gebeurt nog steeds helemaal niets als ik op de signup button druk hoor.

dit is mijn code nu:
  1. <html>
  2. <head>
  3. <title>Mijn eerste php script</title>
  4. <script language="JavaScript" type="text/javascript">
  5. <!--
  6. function check()
  7. {
  8. if ((document.form3.usernamecheck.checked == true)&&(document.form3.nameiscorrect2.checked == true)&&(document.form3.agree.checked == true))
  9. {
  10. document.form3.verzenden.disabled = false;
  11. } else
  12. {
  13. document.form3.verzenden.disabled = true;
  14. }
  15. }
  16. -->
  17. </script>
  18. </head>
  19. <body>
  20. <?php
  21. if (!isset($_POST['verzenden'])){
  22. ?>
  23. <form name="form3" method="post">
  24. <center>
  25. <div style="border-collapse:collapse;border:1px solid;width:750px">
  26. <center>
  27. <table border="0" bordercolor="" style="border-collapse:collapse;" width="100%">
  28. <tr>
  29. <th height="30" bgcolor="darkblue" align="center" colspan="3"><font size="5">Registrations Profile</font></th>
  30. </tr>
  31.  
  32. <tr>
  33. <td colspan="3" bgcolor="blue"><font color="">&nbsp;&nbsp;&nbsp;Vitals - pay careful attention to what you enter, it's hard to log in if you mess any of it up</font></td>
  34. </tr>
  35.  
  36. <tr>
  37. <td width="20%" valign="bottom">Username:</td>
  38. <td><font size="2"> This is required to be exactly the same as your Kings of Chaos username; the system will not work with any other name. Watch out for capitalization. (To be sure you get the right name, simply go to Command Center in Kings of Chaos, highlight your name at the top right corner of the User Info table, and paste it here.)<font></td>
  39. </tr>
  40.  
  41. <tr>
  42. <td valign="top"><input type="textinput" name="username" size="20" value=""/></td>
  43. <td><span id="spanuser" style="display:none"><font color="red">No valid Username!</font></span><input type="checkbox" name="usernamecheck" onclick="javascript:check();"/>OK, I checked my username at Kings of Chaos and put it in the box correctly. <b>(MUST be checked)</b></td>
  44. </tr>
  45.  
  46. <tr>
  47. <td width="20%" valign="bottom">Email address:</td>
  48. </tr>
  49.  
  50. <tr>
  51. <td valign="top"><input type="textinput" name="email" size="20" value=""/>&nbsp;&nbsp;</td>
  52. <td><span id="spanemail"style="display:none"><font color="red">No valid Emailaddress!</font></span><font color="red"> If you use a free webmail service such as Yahoo! or Hotmail, it is highly likely that your password will disappear into their spam filters. Please make sure that you NOTE DOWN YOUR PASSWORD when it appears on this site in a moment.</font></td>
  53. </tr>
  54.  
  55. <tr>
  56. <td width="20%" valign="bottom">Kings of Chaos Link:</td>
  57. </tr>
  58.  
  59. <tr>
  60. <td colspan="2"><input type="textinput" name="userlink" size="50" value=""/>&nbsp;&nbsp;<span id="spanlink" style="display:none"><font color="red">No valid Uniquelink!</font></span>
  61. </td>
  62. </tr>
  63.  
  64. <tr>
  65. <td colspan="2" height="40"></td>
  66. </tr>
  67.  
  68. <tr>
  69. <td colspan="2" height="30"></td>
  70. </tr>
  71.  
  72. <tr>
  73. <td width="20%" valign="bottom">Current Army Size:</td>
  74. </tr>
  75.  
  76. <tr>
  77. <td width="20%" valign="bottom"><input type="textinput" name="armysize" size="5" />
  78. <select name="race">
  79. <option value="Humans">Humans</option>
  80. <option value="Dwarves">Dwarves</option>
  81. <option value="Elves">Elves</option>
  82. <option value="Orcs">Orcs</option>
  83. </select>
  84. &nbsp;&nbsp;<span id="spanamry"style="display:none"><font color="red">No valid Armysize!</font></span>
  85. </td>
  86. </tr>
  87.  
  88. <tr>
  89. <td colspan="2" height="10"></td>
  90. </tr>
  91.  
  92. <tr bgcolor="darkblue">
  93. <td colspan="2" height="30"><font size="5"><b>Alliance</b></font></td>
  94. </tr>
  95.  
  96. <tr>
  97. <td>
  98. <select name="alliance">
  99. <option value="0" selected="selected" >Select an alliance from the list</option>
  100. <option value="1" >LOG member</option>
  101. <option value="2" >Lordclicker User</option>
  102. </select>
  103. </td>
  104. <td>&nbsp;Please select 'Lordclicker User', unless you are a member of Lords of Gondor.&nbsp;<span id="spanalliance" style="display:none"><font color="red">Please select an alliance!</font></span><br /><input type="checkbox" onclick="javascript:check();" name="nameiscorrect2"/>I have selected an appropriate alliance <b>(MUST be checked)</b></td>
  105. </tr>
  106.  
  107. <tr bgcolor="darkblue">
  108. <td colspan="2" height="30"><font size="5"><b>Agreement</b></font></td>
  109. </tr>
  110.  
  111. <tr>
  112. <td colspan="2">
  113. You need to have checked all three check boxes in this form.<br /><br />
  114. Checking this one signifies one of the following two: <ol><li>that you are a member of Lords of Gondor or are in its command chain, and as such, you will not attack or attempt to recruit as an officer ANYONE in Lords of Gondor or its command chain, and that you will uphold the high standards of gameplay and citizenship that have come to be the trademarks of Lords of Gondor; that you will not break Kings of Chaos rules, spam or harass people in the game or out; that you understand you must most definitely kick ass in the game. (That's what we're all about)<br /><br /><b>or</b><br/><br/></li><li>that you agree that you are NOT in an alliance which is an enemy of Lords of Gondor</li></ol>
  115. <input type="checkbox" name="agree" onclick="javascript:check();"/> I agree to one of the two above statements. <b>(MUST be checked)</b>
  116. </td>
  117. </tr>
  118.  
  119. <tr>
  120. <td colspan="2" height="10"></td>
  121. </tr>
  122.  
  123. <tr>
  124. <td colspan="2" align="center"><input type="button" name="verzenden" value="Sign up" disabled/></td>
  125. </tr>
  126.  
  127. <tr>
  128. <td colspan="2" height="10"></td>
  129. </tr>
  130.  
  131. </table>
  132. </center>
  133. </div>
  134. <br />
  135. </center>
  136. </form>
  137. <?php
  138. } elseif(isset($_POST['verzenden'])){
  139. {if(empty($username)) {
  140. ?>
  141. <script>document.getElementById('spanuser').style.display='block';</script>
  142. <?php
  143. ;}
  144. if(empty($email)) {
  145. ?>
  146. <script>document.getElementById('spanemail').style.display='block';</script>
  147. <?php
  148. ;}
  149. if(empty($userlink)) {
  150. ?>
  151. <script>document.getElementById('spanlink').style.display='block';</script>
  152. <?php
  153. ;}
  154. if(empty($armysize)) {
  155. ?>
  156. <script>document.getElementById('spanarmy').style.display='block';</script>
  157. <?php
  158. ;}
  159. if($_POST['alliance'] == 0)
  160. {
  161. ?>
  162. <script>document.getElementById('spanalliance').style.display='block';</script>
  163. <?php
  164. ;}
  165. else{ echo "Info succesvol toegevoegd aan de database";}
  166. }}
  167. ?>
  168. </body>
  169. </html>
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.203s