Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Walidacja Captcha
Ajjlechu
post 2.01.2021, 16:14:11
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 2.01.2021

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


Witam,

Jestem nowy na Forum oraz potrzebuje waszej pomocy bo nie moge sobie poradzic z Captcha.

Problem jest tylko jeden ale dla mnie trudny, wszystko dziala jak nalezy ale jak ktos przepisze niepoprawnie captche to i tak wiadomosc zostaje wyslana...

Nie moge sobie poradzic zeby to razem zgrac z php

mam nadzieje ze ktos bylby tak mily i pomoglby mi albo podpowiedzial jak ta linijke w php dostosowac aby to dzialalo..


czyli najlatwiej mowiac jak moge tutdaj dodac linijke ktora wywali blad ze captcha zostala zle przepisana

  1. $json=array("status"=>1,"msg"=>"<p class='status_ok'>Your message has been sent correctly.<br>Within a few seconds you will receive a copy of the sent E-Mail.<br>Thank you very much for using the service from<br>blabla</p>");
  2. }
  3. }
  4. else{
  5. $json=array("status"=>0,"msg"=>"<p class='status_err'>A script error has occurred.<br>Don`t worry, it's okay :)<br>Please try to send the same message again.</p>");
  6. }
  7. }
  8. else{
  9. $json=array("status"=>0,"msg"=>"<p class='status_err'>Please complete the required<br>fields marked with an asterisk *<br>and try to send the message again.</p>");
  10. }
  11. echo json_encode($json);
  12. ?>



Ponizej przesylam caly kod

ENkontaktmail.php

  1. <?php
  2. header("content-type: application/json; charset=UTF-8");
  3. $fname=isset($_POST['fname']) ? $_POST['fname'] : "";
  4. $sname=isset($_POST['sname']) ? $_POST['sname'] : "";
  5. $email=isset($_POST['email']) ? $_POST['email'] : "";
  6. $phone=isset($_POST['phone']) ? $_POST['phone'] : "";
  7. $titel=isset($_POST['titel']) ? $_POST['titel'] : "";
  8. $CaptchaInput=isset($_POST['CaptchaInput']) ? $_POST['CaptchaInput'] : "";
  9. $datenschutz=isset($_POST['datenschutz']) ? $_POST['datenschutz'] : "";
  10. $message=isset($_POST['message']) ? $_POST['message'] : "";
  11. if($fname && $email && $sname && $titel && $message && $CaptchaInput && $datenschutz){
  12. $headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: 8bit";
  13. $message_body = '
  14. <!DOCTYPE html>
  15.  
  16. </html>
  17. ';
  18. $message_body1 = '
  19. <!DOCTYPE html>
  20.  
  21. </html>
  22. ';
  23. if(mail("sara@blabla.ch","$titel",$message_body,$headers,"-f sara@blabla.ch")){
  24. if(mail("$email","$titel",$message_body1,$headers,"-f sara@blabla.ch")){
  25. $json=array("status"=>1,"msg"=>"<p class='status_ok'>Your message has been sent correctly.<br>Within a few seconds you will receive a copy of the sent E-Mail.<br>Thank you very much for using the service from<br>blabla</p>");
  26. }
  27. }
  28.  
  29.  
  30.  
  31. else{
  32. $json=array("status"=>0,"msg"=>"<p class='status_err'>A script error has occurred.<br>Don`t worry, it's okay :)<br>Please try to send the same message again.</p>");
  33. }
  34. }
  35. else{
  36. $json=array("status"=>0,"msg"=>"<p class='status_err'>Please complete the required<br>fields marked with an asterisk *<br>and try to send the message again.</p>");
  37. }
  38. echo json_encode($json);
  39. ?>


contact.html

  1. <div class="site-section bg-light text-black">
  2. <div class="container">
  3. <div class="row">
  4. <div class="col-md-7 mb-5">
  5. <form method="post" action="../../php/ENkontaktmail.php" id="contact_form" onsubmit="return checkform(this);" class="p-5 bg-white">
  6. <h2 class="text-center display-3">Contact form</h2>
  7. <div class="row form-group">
  8. <div class="row form-group">
  9. <div class="col-md-12">
  10. <div class="text-center" id="CaptchaDiv"></div>
  11. <input type="hidden" id="txtCaptcha">
  12. <div class="text-center"><label for="CaptchaInput">Please enter the five-digit security code*</label>
  13. <input type="text" minlength=5 maxlength=5 name="CaptchaInput" id="CaptchaInput" required="required" placeholder="Security code" class="form-control text-center"></div>
  14. </div>
  15. </div>
  16. <div class="row text-center form-group">
  17. <div class="col-md-12">
  18. <input type="submit" value="Send" class="btn btn-black py-3 px-5">
  19. <div class="text-center text-primary" id="send_form_status"></div>
  20. </div>
  21. </div>
  22. </form>
  23. </div>
  24. </div>
  25. </div>



generator captcha .js

  1. function ValidCaptcha(){
  2. [b]var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
  3. var str2 = removeSpaces(document.getElementById('CaptchaInput').value);[/b]
  4. if (str1 == str2){
  5. return true;
  6. }else{
  7. return false;
  8. }
  9. }
  10. function removeSpaces(string){
  11. return string.split(' ').join('');
  12. }
  13. var a = Math.ceil(Math.random() * 9)+ '';
  14. var b = Math.ceil(Math.random() * 9)+ '';
  15. var c = Math.ceil(Math.random() * 9)+ '';
  16. var d = Math.ceil(Math.random() * 9)+ '';
  17. var e = Math.ceil(Math.random() * 9)+ '';
  18. var code = a + b + c + d + e;
  19. document.getElementById("txtCaptcha").value = code;
  20. document.getElementById("CaptchaDiv").innerHTML = code;



tak to wyglada



Ten post edytował Ajjlechu 2.01.2021, 16:28:27
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 Wersja Lo-Fi Aktualny czas: 29.06.2025 - 17:59