Jump to content

Pop up error msg in php code


justspiffy

Recommended Posts

Hey guys,

 

Just a quick questions Im wondering if someone can help me with. I have created a form and it uses CAPTCHA to verify the person filling out the form is human. If they will the form out and put the wrong word into the CAPCTHA field, it loads an error on a new page that says "he reCAPTCHA wasn't entered correctly. Go back and try it again." What i would like it to do, instead of loading in a new page and them losing the information they have put in the form, is for a pop up to come up and give the error instead.

 

Anyone know how I could go about that?

 

Here is the code:

 

<?php
   } else {
      error_reporting(0);
  

require_once('recaptchalib.php');
$privatekey = "6Lc3CAoAAAAAACXdton7ORpQm_C23NwVdumiRFWK";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}

  
      $recipient = 'contact@justspiffy.ca';
  $Num_ID = stripslashes($_POST['ID_Number']);
  $confirmation = md5($ID_Number . time());
      $First_Name = stripslashes($_POST['Surname']);
  $Last_Name = stripslashes($_POST['Given_name']);
  $Email_Address = stripslashes($_POST['Email_Address']);
      $Change_Con = stripslashes($_POST['Contact_Change']);
      $Curr_Addy = stripslashes($_POST['Address']);
  $Curr_Municipality = stripslashes($_POST['Municipality']);
      $Curr_Province = stripslashes($_POST['Province']);
  $PostalCode = stripslashes($_POST['Postal_Code']);
      $Curr_Home = stripslashes($_POST['Phone_Home']);
      $Curr_Work = stripslashes($_POST['Phone_Work']);
      $Work_Ext = stripslashes($_POST['Phone_Work_Extension']);
  $Cred_Type = stripslashes($_POST['Card_Type']);
  $Curr_Card_Name = stripslashes($_POST['CreditCardName']);
      $Curr_Card_Num = stripslashes($_POST['CardNumber']);
      $Curr_Card_Num1 = stripslashes($_POST['CardNumber1']);
      $Curr_Card_Num2 = stripslashes($_POST['CardNumber2']);
      $Curr_Card_Num3 = stripslashes($_POST['CardNumber3']);
  $Month_Exp = stripslashes($_POST['Expiry_Month']);
      $Year_Exp = stripslashes($_POST['Expiry_Year']);
      $Paid_Amo = stripslashes($_POST['Amount_Paid']);
  $Name_Vet = stripslashes($_POST['vet_clinic_name']);
  $Name_Ani1 = stripslashes($_POST['Animal1_Name']);
      $Rab_Ani1_Mon = stripslashes($_POST['Rabies_Month_Animal1']);
      $Rab_Ani1_Year = stripslashes($_POST['Rabies_Year_Animal1']);
      $Name_Ani2 = stripslashes($_POST['Animal2_Name']);
      $Rab_Ani2_Mon = stripslashes($_POST['Rabies_Month_Animal2']);
  $Rab_Ani2_Year = stripslashes($_POST['Rabies_Year_Animal2']);
  $Name_Ani3 = stripslashes($_POST['Animal3_Name']);
  $Rab_Ani3_Mon = stripslashes($_POST['Rabies_Month_Animal3']);
  $Rab_Ani3_Year = stripslashes($_POST['Rabies_Year_Animal3']);
  $Cat_Dog = stripslashes($_POST['DogOrCat']);
  $Comment = stripslashes($_POST['Notes']);
      
      $sendto = $_POST['Email_Address'];
      $headers = "From: $recipient\r\n\r\n";
      $subject = "Licence Renewal Request $confirmation\n";
      $message = "Thank you for registering your pet with London Animal Care Centre.\n
			  Please keep this email as proof of your application for your 
			  dog licence or cat identification tag.

			  Your confirmation Id is $confirmation\n
			    
			  If you have any questions or concerns please call (519)685-1330
			  and have your confirmation id available.\n
			  Please allow 3 to 6 weeks for processing and delivery of your tags.\n
  
      ID #: $Num_ID\r\n
      Name: $First_Name  $Last_Name\r\n
      E-Mail Address: $Email_Address\r\n
      Have you had a change in address or phone number over the last year?: $Change_Con\r\n
      Address: $Curr_Addy\r\n
      Municipality: $Curr_Municipality\r\n
      Province: $Curr_Province\r\n
  Postal Code: $PostalCode\r\n
      Phone # - Home: $Curr_Home\r\n
      Phone # - Work: $Curr_Work\r\n
      Work Ext: $Work_Ext\r\n
      Card Type: $Cred_Type\r\n
      Name of Cardholder: $Curr_Card_Name\r\n
      Card #: XXXX-XXXX-XXXX-$Curr_Card_Num3\r\n
      Expiry Date: $Month_Exp  $Year_Exp\r\n
      Please indicate amount to be paid: $Paid_Amo\r\n
      Veterinarian Clinic Name: $Name_Vet\r\n
      Name of First Animal: $Name_Ani1\r\n
      Month and Year of Vaccination: $Rab_Ani1_Mon  $Rab_Ani1_Year\r\n
  Name of Second Animal: $Name_Ani2\r\n
      Month and Year of Vaccination: $Rab_Ani2_Mon  $Rab_Ani2_Year\r\n
      Name of Third Animal: $Name_Ani3\r\n
      Month and Year of Vaccination: $Rab_Ani3_Mon  $Rab_Ani3_Year\r\n
      Breed Certification: $Cat_Dog\r\n
      Notes: $Comment\r\n
      ";
      // Send mail to customer, refer to http://php.net/manual/en/function.mail.php
      mail($sendto, $subject, $message, $headers);
      if (!mail) {
          echo "Message failed to send, please notify our Web Team.";
      } else {
          echo nl2br ("<center><br><br><br><br><br><br><br><br><br><br>Thank you. Your request has been sent and we will contact you shortly.<br><br><br><br><br><br><br><br><br><br></center>");
      }
      // Send mail to company
      $to = "contact@justspiffy.ca"; // who gets this one?
      $message = "Thank you for registering your pet with London Animal Care Centre.\n
			  Please keep this email as proof of your application for your 
			  dog licence or cat identification tag.<br />

			  Your confirmation Id is $confirmation\n
			    
			  If you have any questions or concerns please call (519)685-1330
			  and have your confirmation id available.\n
			  Please allow 3 to 6 weeks for processing and delivery of your tags.\n
  
      ID #: $Num_ID\r\n
      Name: $First_Name  $Last_Name\r\n
      E-Mail Address: $Email_Address\r\n
      Have you had a change in address or phone number over the last year?: $Change_Con\r\n
      Address: $Curr_Addy\r\n
      Municipality: $Curr_Municipality\r\n
      Province: $Curr_Province\r\n
  Postal Code: $PostalCode\r\n
      Phone # - Home: $Curr_Home\r\n
      Phone # - Work: $Curr_Work\r\n
      Work Ext: $Work_Ext\r\n
      Card Type: $Cred_Type\r\n
      Name of Cardholder: $Curr_Card_Name\r\n
      Card #: $Curr_Card_Num  $Curr_Card_Num1  $Curr_Card_Num2  $Curr_Card_Num3\r\n
      Expiry Date: $Month_Exp  $Year_Exp\r\n
      Please indicate amount to be paid: $Paid_Amo\r\n
      Veterinarian Clinic Name: $Name_Vet\r\n
      Name of First Animal: $Name_Ani1\r\n
      Month and Year of Vaccination: $Rab_Ani1_Mon  $Rab_Ani1_Year\r\n
  Name of Second Animal: $Name_Ani2\r\n
      Month and Year of Vaccination: $Rab_Ani2_Mon  $Rab_Ani2_Year\r\n
      Name of Third Animal: $Name_Ani3\r\n
      Month and Year of Vaccination: $Rab_Ani3_Mon  $Rab_Ani3_Year\r\n
      Breed Certification: $Cat_Dog\r\n
      Notes: $Comment\r\n
      ";
      mail($to, $subject, $message, $headers);
       if (!mail) {
          echo "Message failed to send. Please notify our Web Team.";
      } else {
          // something here to notify the web team if it fails.
      }
}
?>

 

Link to comment
Share on other sites

PHP is server side, so if you want to have a pop up happen without a page load - you will have to do it with AJAX. 

 

Basically any time you want to do something in PHP that *DOESN'T* require a page load, you are looking are going to have to use (at least some) javascript.

 

Need any help getting pointed in the right direction?

Link to comment
Share on other sites

I tried using some javascript (though I dont know to much about it) but it didnt seem to work for me.

 

I tried the following:

 

<?php

  } else {

      error_reporting(0);

 

require_once('recaptchalib.php');

$privatekey = "6Lc3CAoAAAAAACXdton7ORpQm_C23NwVdumiRFWK";

$resp = recaptcha_check_answer ($privatekey,

$_SERVER["REMOTE_ADDR"],

$_POST["recaptcha_challenge_field"],

$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {

 

die('<script type="text/javascript">

alert("The reCAPTCHA wasn't entered correctly. Go back and try it again." .

"(reCAPTCHA said: " . $resp->error . ")");

</script>

}

 

but it didnt work :(

 

am i close? ha

Link to comment
Share on other sites

I tried using some javascript (though I dont know to much about it) but it didnt seem to work for me.

 

I tried the following:

 

<?php

  } else {

      error_reporting(0);

 

require_once('recaptchalib.php');

$privatekey = "6Lc3CAoAAAAAACXdton7ORpQm_C23NwVdumiRFWK";

$resp = recaptcha_check_answer ($privatekey,

$_SERVER["REMOTE_ADDR"],

$_POST["recaptcha_challenge_field"],

$_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {

 

die('<script type="text/javascript">

alert("The reCAPTCHA wasn't entered correctly. Go back and try it again." .

"(reCAPTCHA said: " . $resp->error . ")");

</script>

}

 

but it didnt work :(

 

no, that wouldn't work 'cause the markup is a mess.

 

you have </script> outside the die();  you didn't escape the ' in wasn't (wasn\'t), and so on.

 

this will work for you:

 

die('
<script type="text/javascript">
	alert("The reCAPTCHA wasn\'t entered correctly. Go back and try it again.\n\n(reCAPTCHA said: '. $resp->error . ')");
</script>
');

Link to comment
Share on other sites

One must also question the usability of a form that tells you to manually return to the form they just submitted.

 

oh yes.  that code has madness written all over it.  i just corrected the problem at hand.  if the OP wishes to go through proper error handling, i have no problem in addressing that, either.

Link to comment
Share on other sites

When I use that code you provided me, it work, except it attempts to send the form through and loads a blank page with the pop up. Is there a way to do it so it just gives the pop up and stays on the same page with the form still open and everything they have put in the form still there?

 

Also, and this may be what you were talking about..

 

When i put a incorrect passcode in the CAPTCHA it gives me the error, but when i click back and put the correct one in, it still says it is wrong??

The only way I found around it is when I hit refresh and type it in, then it will send. Even if I put the incorrect passcode in it still sends ha. Not sure why that is? :(

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.