Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  • Thread Tools
  • Rate This Thread
  1. #1
    New to the CF scene
    Join Date
    May 2015
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    reCAPTCHA - If (error==true) { STAY ON THE SAME PAGE } else {do what you are told to}

    Hello dear friends. I tried to be funny in making the title of this post, hope you can understand what I want, if not
    {
    I have a form, for online request towards an ISP company. The reCAPTCHA works but if there is an error it takes us to a blank page with simple text either "no verification code inputted" or "wrong verification code inputted" .
    And as this is a FORM which clients fill out themselves , it would be a shame if something happened to it just cuzz of a simple mistake on the reCAPTCHA.
    }

    I tried a few methods but it didnt really work

    Here is the HTML code

    Code:
    <body>
        <h1>Online Request</h1>
        <form action="emailer.php" method="POST" accept-charset="UTF-8">
            <div>
                <p> Имена</p>
                <input name="name" type="text"> <br/>
            </div>
            <div>
              <p> Адрес на заявката</p>
              <input name="address" type="text"> <br/>
            </div>
            <div>
                <p> Телефон за връзка</p>
                <input type="text" name="number" min="10" max="10">
                <br>
            </div>
            <div>
                <p> Вид услуга - Internet </p> <br/>
                <input name="servicetypeINT" type="radio" value="30"><span class="checkbox"> Internet Value - 30Mpbs </span> <br/>
                <input name="servicetypeINT" type="radio" value="60"><span class="checkbox"> Internet Mania - 60 Mbps </span><br/>
                <input name="servicetypeINT" type="radio" value="100"><span class="checkbox"> Internet Extreme - 100Mbps</span> <br/>
                <input name="servicetypeINT" type="radio" value="150"><span class="checkbox"> Internet Pro - 150Mpbs</span><br/>
            </div>
            <hr/>
            <div>
                <p> Вид услуга - Телевизия</p> <br/>
                <input name="servicetypeTV" type="radio" value="anal"><span class="checkbox"> Аналогова телевизия - 50 канала </span> <br/>
                <input name="servicetypeTV" type="radio" value="start"><span class="checkbox"> Start TV - 40+ Цифрови канала </span><br/>
                <input name="servicetypeTV" type="radio" value="comfort"><span class="checkbox"> Comfort TV - 160+ Цифрови канала</span> <br/>
                <input name="servicetypeTV" type="radio" value="mania"><span class="checkbox"> Mania TV - 160+ Цифрови / 20+ HD канала</span><br/>
            </div>
            <hr/>
            <div>
                <p> Вид заявка (Експресна / Нормална) </p> <br/>
                <input name="request" type="radio" value="normal"> <span class="checkbox"> Нормална заявка (7 работни дни - без доплащане) </span> <br/>
                <input name="request" type="radio" value="express"> <span class="checkbox"> Експресна заявка (24 часа - 10 лв.) </span> <br/>
            </div>
                <div>
                <p> Допълнителна информация - упътвания или особенности, за които екипите ни трябва да знаят при изпълняването на заявката</p>
                <textarea cols="30" name="comment" rows="9"></textarea>
                <br/>
                </div>
            <div>
            <input name="submit" type="submit" value="Изпрати"> </div>
            <div class="g-recaptcha" data-sitekey="6LegpgYTAAAAAM5HEaPoHE4UqUHYYNfEYFnXqW8p"></div>
            <span class='msg'><?php echo $msg; ?></span>
        </form>
    </body>
    
    </html>
    we only need this, Im not gonna give you the head since it contains the CSS-supposed-to-be and it takes half the code.

    Here is the PHP
    Code:
    <?php
    
    session_start();
    
    $msg='';
    if($_SERVER["REQUEST_METHOD"] == "POST")
    {
    $recaptcha=$_POST['g-recaptcha-response'];
    if(!empty($recaptcha))
    {
    include("getCurlData.php");
    $google_url="https://www.google.com/recaptcha/api/siteverify";
    $secret='6LegpgYTAAAAABK9Nd45_DfAPu7_gwHro9pj902B';
    $ip=$_SERVER['REMOTE_ADDR'];
    $url=$google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
    $res=getCurlData($url);
    $res= json_decode($res, true);
    //reCaptcha success check
    if($res['success'])
    {
    
    
    
    
    
      $headers  = 'MIME-Version: 1.0' . "\r\n";
      $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    
      if(isset($_POST['submit'])) {
      $to = "[email protected]";
      $subject = "New Internet and/or TV request";
    
      // data the visitor provided
      $name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
      $phone_field = filter_var($_POST['number']);
      $address_field = filter_var($_POST['address'], FILTER_SANITIZE_STRING);
      $selectedINT_field = filter_var($_POST['servicetypeINT']);
      $selectedTV_field = filter_var($_POST['servicetypeTV']);
      $selectedRQ_field = filter_var($_POST['request']);
      $comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
    
    
      //constructing the message
      $body = "
      From: $name_field <br/>
      Address: $address_field <br/>
      Phone number: $phone_field <br/>
      Selected Services: <br/> Internet: $selectedINT_field || TV: $selectedTV_field <br/>
      Type of request: $selectedRQ_field <br/>
      Message:<br/>$comment ";
    
      // ...and away we go!
      mail($to, $subject, $body, $headers);
    
      // redirect to confirmation
      header('Location: confirmation.html');
      }
      else {
      // handle the error somehow
      echo "Грешка в попълването на формата";
      }
    
    
    
    
    
    
    }
    else
    {
    echo "Въвели сте грешен код за потвърждаване (reCAPTCHA)! Върнете се обратно и опитайте отново";
    }
    
    }
    else
    {
    echo "Не сте въвели код за потвърждаване (reCAPTCHA)! Върнете се обратно и опитайте отново";
    }
    
    }
    
    ?>
    I tried a funny thing, instead of redirecting form action to emailer.php , i tried writing the code of the PHP in the action of the form it self. As pure code for action. Well it didnt happen... for some reason the closing > was defined as literal , and not as part of the form tag, who knows why maybe cuzz i had a ton of quotes used in the PHP (go figure) .

    I am here to ask you for a favor. Can you give me suggestions on how I can do it so that the error massage is displayed on the page you are currently on , and not on the php action page ?

  2. #2
    New to the CF scene
    Join Date
    May 2015
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by depkata02 View Post
    Hello dear friends. I tried to be funny in making the title of this post, hope you can understand what I want, if not
    {
    I have a form, for online request towards an ISP company. The reCAPTCHA works but if there is an error it takes us to a blank page with simple text either "no verification code inputted" or "wrong verification code inputted" .
    And as this is a FORM which clients fill out themselves , it would be a shame if something happened to it just cuzz of a simple mistake on the reCAPTCHA.
    }

    I tried a few methods but it didnt really work

    Here is the HTML code

    Code:
    <body>
        <h1>Online Request</h1>
        <form action="http://www.codingforums.com/emailer.php" method="POST" accept-charset="UTF-8">
            <div>
                <p> Имена</p>
                <input name="name" type="text"> <br/>
            </div>
            <div>
              <p> Адрес на заявката</p>
              <input name="address" type="text"> <br/>
            </div>
            <div>
                <p> Телефон за връзка</p>
                <input type="text" name="number" min="10" max="10">
                <br>
            </div>
            <div>
                <p> Вид услуга - Internet </p> <br/>
                <input name="servicetypeINT" type="radio" value="30"><span class="checkbox"> Internet Value - 30Mpbs </span> <br/>
                <input name="servicetypeINT" type="radio" value="60"><span class="checkbox"> Internet Mania - 60 Mbps </span><br/>
                <input name="servicetypeINT" type="radio" value="100"><span class="checkbox"> Internet Extreme - 100Mbps</span> <br/>
                <input name="servicetypeINT" type="radio" value="150"><span class="checkbox"> Internet Pro - 150Mpbs</span><br/>
            </div>
            <hr/>
            <div>
                <p> Вид услуга - Телевизия</p> <br/>
                <input name="servicetypeTV" type="radio" value="anal"><span class="checkbox"> Аналогова телевизия - 50 канала </span> <br/>
                <input name="servicetypeTV" type="radio" value="start"><span class="checkbox"> Start TV - 40+ Цифрови канала </span><br/>
                <input name="servicetypeTV" type="radio" value="comfort"><span class="checkbox"> Comfort TV - 160+ Цифрови канала</span> <br/>
                <input name="servicetypeTV" type="radio" value="mania"><span class="checkbox"> Mania TV - 160+ Цифрови / 20+ HD канала</span><br/>
            </div>
            <hr/>
            <div>
                <p> Вид заявка (Експресна / Нормална) </p> <br/>
                <input name="request" type="radio" value="normal"> <span class="checkbox"> Нормална заявка (7 работни дни - без доплащане) </span> <br/>
                <input name="request" type="radio" value="express"> <span class="checkbox"> Експресна заявка (24 часа - 10 лв.) </span> <br/>
            </div>
                <div>
                <p> Допълнителна информация - упътвания или особенности, за които екипите ни трябва да знаят при изпълняването на заявката</p>
                <textarea cols="30" name="comment" rows="9"></textarea>
                <br/>
                </div>
            <div>
            <input name="submit" type="submit" value="Изпрати"> </div>
            <div class="g-recaptcha" data-sitekey="6LegpgYTAAAAAM5HEaPoHE4UqUHYYNfEYFnXqW8p"></div>
            <span class='msg'><?php echo $msg; ?></span>
        </form>
    </body>
    
    </html>
    we only need this, Im not gonna give you the head since it contains the CSS-supposed-to-be and it takes half the code.

    Here is the PHP
    Code:
    <?php
    
    session_start();
    
    $msg='';
    if($_SERVER["REQUEST_METHOD"] == "POST")
    {
    $recaptcha=$_POST['g-recaptcha-response'];
    if(!empty($recaptcha))
    {
    include("getCurlData.php");
    $google_url="https://www.google.com/recaptcha/api/siteverify";
    $secret='6LegpgYTAAAAABK9Nd45_DfAPu7_gwHro9pj902B';
    $ip=$_SERVER['REMOTE_ADDR'];
    $url=$google_url."?secret=".$secret."&response=".$recaptcha."&remoteip=".$ip;
    $res=getCurlData($url);
    $res= json_decode($res, true);
    //reCaptcha success check
    if($res['success'])
    {
    
    
    
    
    
      $headers  = 'MIME-Version: 1.0' . "\r\n";
      $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
    
      if(isset($_POST['submit'])) {
      $to = "[email protected]";
      $subject = "New Internet and/or TV request";
    
      // data the visitor provided
      $name_field = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
      $phone_field = filter_var($_POST['number']);
      $address_field = filter_var($_POST['address'], FILTER_SANITIZE_STRING);
      $selectedINT_field = filter_var($_POST['servicetypeINT']);
      $selectedTV_field = filter_var($_POST['servicetypeTV']);
      $selectedRQ_field = filter_var($_POST['request']);
      $comment = filter_var($_POST['comment'], FILTER_SANITIZE_STRING);
    
    
      //constructing the message
      $body = "
      From: $name_field <br/>
      Address: $address_field <br/>
      Phone number: $phone_field <br/>
      Selected Services: <br/> Internet: $selectedINT_field || TV: $selectedTV_field <br/>
      Type of request: $selectedRQ_field <br/>
      Message:<br/>$comment ";
    
      // ...and away we go!
      mail($to, $subject, $body, $headers);
    
      // redirect to confirmation
      header('Location: confirmation.html');
      }
      else {
      // handle the error somehow
      echo "Грешка в попълването на формата";
      }
    
    
    
    
    
    
    }
    else
    {
    echo "Въвели сте грешен код за потвърждаване (reCAPTCHA)! Върнете се обратно и опитайте отново";
    }
    
    }
    else
    {
    echo "Не сте въвели код за потвърждаване (reCAPTCHA)! Върнете се обратно и опитайте отново";
    }
    
    }
    
    ?>
    I tried a funny thing, instead of redirecting form action to emailer.php , i tried writing the code of the PHP in the action of the form it self. As pure code for action. Well it didnt happen... for some reason the closing > was defined as literal , and not as part of the form tag, who knows why maybe cuzz i had a ton of quotes used in the PHP (go figure) .

    I am here to ask you for a favor. Can you give me suggestions on how I can do it so that the error massage is displayed on the page you are currently on , and not on the php action page ?
    use perl instead.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •