Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Problem z captcha w formularzu
Forum PHP.pl > Forum > Przedszkole
airgucio
Witajcie mam formularz z kilkoma polami z funkcją sparwdzania czy pole zostało wypełnione, niestety od pewnego czasu atakuje mnie spam smile.gif i postanowiłem dodać captcha do formularza. Dodałem skrypt pokazuje się obrazek a w nim tekst można nawet go odwsieżyć tongue.gif , ale coś nie działa bo moge nadal wysyłać wiadomość bez podania kodu . problem napewno leży w dodaniu tego fragmentu kodu

  1.  
  2. <?php
  3. include_once $_SERVER['DOCUMENT_ROOT'] . 'http://xxxxxxxxxxxxxxx/securimage/securimage.php';
  4. $securimage = new Securimage();
  5.  
  6. if ($securimage->check($_POST['captcha_code']) == false) {
  7. // the code was incorrect
  8. // you should handle the error so that the form processor doesn't continue
  9.  
  10. // or you can use the following code if there is no validation or you do not know how
  11. echo "The security code entered was incorrect.<br /><br />";
  12. echo "Please go <a href='java script:history.go(-1)'>back</a> and try again.";
  13. }
  14. ?>
  15.  
  16.  


Bo niezabardzo wiem gdzie go dać i czy nie potrzebuje on modyfikacji


Oto mój kod wraz ze wstawionym fragment :

  1.  
  2. <?php session_start(); ?>
  3. <?php if(isset($page['sended']) && $page['sended'] == 1):?>
  4. <p class="tcent">
  5. <?php if($page['status'] == 1):?>
  6. <span class="biggerb">Thank You for filling the form.</span><br />
  7. <?php else: ?>
  8. <?php if($page['status'] == 2):?>
  9. <span class="bigger redb">Wrong email.</span><br />
  10. <?php else: ?>
  11. <span class="bigger redb">Error. Please correct data in form.</span><br />
  12.  
  13. <?php
  14. include_once $_SERVER['DOCUMENT_ROOT'] . 'http://xxxxxxxxxxxxx/securimage/securimage.php';
  15. $securimage = new Securimage();
  16.  
  17. if ($securimage->check($_POST['captcha_code']) == false) {
  18. // the code was incorrect
  19. // you should handle the error so that the form processor doesn't continue
  20.  
  21. // or you can use the following code if there is no validation or you do not know how
  22. echo "The security code entered was incorrect.<br /><br />";
  23. echo "Please go <a href='java script:history.go(-1)'>back</a> and try again.";
  24. }
  25. ?>
  26.  
  27. <?php endif; ?>
  28. <?php endif; ?>
  29. <a href="eng/contact_us">back</a>
  30.  
  31.  
  32.  
  33.  
  34. </p>
  35. <?php else: ?>
  36.  
  37.  
  38.  
  39. <noscript><noscript>Correctly working form needs javascript enabled</noscript></noscript>
  40. <form action="" method="post" class="u_form" id="contact_form">
  41. <fieldset>
  42. <table cellpadding="1" cellspacing="1" class="tleft mleft10" width="565">
  43. <tbody>
  44. <tr>
  45. <td width="180"><label for="first_name" class="bld">First name:</label></td>
  46. <td><span class="red bigger">*</span> <input type="text" id="first_name" name="first_name" class="txt longer" /></td>
  47. </tr>
  48. <tr>
  49. <td width="180"><label for="last_name" class="bld">Last name:</label></td>
  50. <td><span class="red bigger">*</span> <input type="text" id="last_name" name="last_name" class="txt longer" /></td>
  51. </tr>
  52. <tr>
  53. <td><label for="email" class="bld">Email:</label></td>
  54. <td><span class="red bgger">*</span> <input type="text" id="email" name="email" class="txt longer" /></td>
  55. </tr>
  56. <tr>
  57. <td><label for="tel" class="bld">Telephone:</label></td>
  58. <td><span class="white bigger">*</span> <input type="text" id="tel" name="tel" class="txt longer" /></td>
  59. </tr>
  60. <tr>
  61. <td><label for="enquiry" class="bld">Your enquiry :</label></td>
  62. <td><span class="red bigger">*</span> <textarea id="enquiry" name="enquiry" class="longer"></textarea></td>
  63.  
  64.  
  65.  
  66. <tr>
  67. <tr>
  68.  
  69. <td ><label for="enquiry" class="bld">Write code below: <p>
  70. <img id="captcha" src="xxxxxxxxxxxxx/securimage/securimage_show.php" alt="CAPTCHA Image" /><p><a href="#" onclick="document.getElementById('captcha').src = 'xxxxxxxxxxxxxxxx/securimage/securimage_show.php?' + Math.random(); return false">[ Different Image ]</a></td>
  71. <td><span class="red bigger"></span><input type="text" name="captcha_code" size="10" maxlength="6" /><br>
  72.  
  73.  
  74.  
  75. </td>
  76. <tr>
  77.  
  78. <td colspan="2" class="tright"><input type="submit" name="send" id="send" class="subm subm_bigger" value="Send" />
  79. </tr>
  80.  
  81.  
  82.  
  83. </tbody>
  84. </table>
  85. </fieldset>
  86. </form><br />
  87.  
  88.  
  89.  
  90.  
  91. <div class="hr"></div><br />
  92.  
  93. <script type="text/javascript">
  94. $(document).ready(function() {
  95. $('#contact_form').validate({
  96. rules: {
  97. first_name: { required: true, minlength: 3},
  98. last_name: { required: true, minlength: 3},
  99. email: {required:true,email: true},
  100. enquiry: {required:true, minlength:5}
  101.  
  102. },
  103. messages: {
  104. first_name: "Field First name is required",
  105. last_name: "Field Last name is required",
  106. email: "Field Email is required",
  107. enquiry: "Field enquiry is required"
  108.  
  109. }
  110. });
  111. });
  112. </script>
  113. <?php endif; ?>
  114.  
  115.  


Proszę o pomoc albo naprowadzenie mnie na dobrą scieżkę, bo siedze już nad tym trochę i nie wiem co zrobić sad.gif
buliq
Co to jest? Jakto przez http questionmark.gif

Kod
include_once $_SERVER['DOCUMENT_ROOT'] . 'http://xxxxxxxxxxxxx/securimage/securimage.php';


Co zwraca to:

Kod
$securimage->check($_POST['captcha_code'])


Coś mi tu nie pasuje, gdzie jest fragment o wysyłce??

Ten if do pokazania błędu powinien być przy pozostałych wynikach walidacji.
Natomiast używasz czegoś takiego: $page['status']
Jak sądzę to to określa czy formularz został poprawnie uzupełniony, to powiedz mi gdzie, twoim zdaniem powinieneś jeszcze dodać walidację captcha?

Zakładaj z góry ze kod który wysyłasz jest niewystarczający. Problem leży w wysyłce wiadomości a nie w formularzu.
airgucio
Dzięki , już sobie poradziłem z tym problemem . Dodałem inny skrypt który narazie działa tongue.gif, a to przez http zrobiłem tylko dla testów bo już miałem dość tego skryptu

Jak by ktoś chciał użyć :


  1.  
  2. <script src="http://code.jquery.com/jquery-1.9.0.js"></script>
  3. <script type="text/javascript" src="jquery.ebcaptcha.js"></script>
  4.  
  5.  
  6. <form method="post" id="form">
  7. <input type="submit">
  8. </form>
  9.  
  10.  
  11. <script type="text/javascript">
  12. $(function(){
  13. $('#form').ebcaptcha();
  14. });
  15. </script>
  16.  
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.