Results 1 to 10 of 10

Thread: Advice for recaptcha edit

  1. #1
    Join Date
    Nov 2011
    Location
    Cider Region
    Posts
    1,132
    Thanks
    158
    Thanked 3 Times in 3 Posts

    Default Advice for recaptcha edit

    I have a working email contact form which has a recaptcha within it.
    On the email contact form there was 2 fields.i have added an extra field but i cant get the 3rd field shown when i receive the email,i just see the existing 2 fields as if my 3rd field was not entered to the form.
    I understand that once the form has been completed and sent it then passes over to a .php file to be handeled.
    I am not sure if it is safe to put the files here as dont they contain the recaptcha keys ??
    Please advise what i should do.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You can put any files you want. If they contain keys, just edit those out. You may not have to though - usually these keys are domain specific and won't work anywhere else.

    To start out though, just give us a link to the page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2011
    Location
    Cider Region
    Posts
    1,132
    Thanks
    158
    Thanked 3 Times in 3 Posts

    Default

    Hi
    Here is the original page in question of which i need changing.

    http://www.ianparsons.info/email.htm

    I would like a field added so it looks like the supplied screen shot.
    I have also added the file if you could edit it for me to look like the screen shot.
    I also also added the php file as i am sure this needs to be altered as well for the alteration to take place thus when i receive an email this new field is shown of which so far i cant get it to ?

    Thanks

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, well you need another label and field obviously and I see you've blocked space out for them in the HTML code already, so like:

    Code:
     <td align="justify" valign="top">
     <p align="center">
    	<font color="#0000FF"><font face="Times New Roman"><label for="name"><b>
    	<font size="6">Name</font></b><font size="6"> *</font></label></font><font size="4">
    	</font>
     </font>
     <p align="center">
     <input type="text" name="name" maxlength="50" size="40"> 
     <p align="center"><label for="photocode"><b>
    	<font face="Times New Roman" style="font-size: 24pt; color: #0000FF">Code From Photo *</font></b></label></p>
    	<p align="center">
     <input type="text" name="photocode" maxlength="50" size="40"> 
    	<p align="center"><font color="#0000FF"><font face="Times New Roman"><label for="email"><b><font size="6">Email Address</font></b><font size="6"> *</font></label></font><font size=4">
    	</font>
     </font>
     </p>
     <p align="center">
     &nbsp;<input type="hidden" name="subject" value="MY WEB SITE ENQUIRY"><input type="text" name="email" maxlength="100" size="40"></td>
    will do. Note that the new field has the name 'photocode'.

    Now all we have to do is to get the PHP file to recognize and use it. That's done in two places, three if you want it to be a required field. If you want it required, add it here:

    Code:
        // validation expected data exists
        if(!isset($_POST['name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['photocode']) ||
    		!isset($_POST['subject']) ||
            !isset($_POST['comments'])) {
            died('We are sorry, but there appears to be a problem with your request.');      
        }
    Then regardless of whether it's required or not, add it here:

    Code:
        $name                      = $_POST['name']; // required
        $email_from                = $_POST['email']; // required
        $photocode                 = $_POST['photocode'];
        $site_url                  = $_POST['site_url']; // required
    	$site_title                = $_POST['site_title'];
        $comments                  = $_POST['comments']; // required
    	$email_subject             = $_POST['subject']; // required
    and here:

    Code:
    	//----------------------------------------------------------------------------------------------
    	// I un-comment this code to places these fields in the email for debugging and valadation
    	//---------------------------------------------------------------------------------------------
    	//$email_message .= "captcha challenge: ".clean_string($recaptcha_challenge_field)."\n"; 
    	//$email_message .= "captcha responce: ".clean_string($recaptcha_response_field)."\n"; 
        $email_message .= "Name: ".clean_string($name)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Photo Code: ".clean_string($photocode)."\n";
        $email_message .= "Comments: ".clean_string($comments)."\n";
    That's it!

    The browser cache may need to be cleared and/or the page refreshed to see changes.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Nov 2011
    Location
    Cider Region
    Posts
    1,132
    Thanks
    158
    Thanked 3 Times in 3 Posts

    Default

    Hi
    Do i just need to copy the yellow text above and paste it into my file here ?

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yes into those places where they go in each file as indicated.

    I noticed one more place in the PHP file if you want the photocode to be a required field:

    Code:
        $error_message = "";
    	if($recaptcha_response_field !=0) {
    		$error_message .= 'Your "captcha" failed Please try again<br />';
    	}	
    	$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
    	if(!preg_match($email_exp,$email_from)) {
    		$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
    	}
     	$string_exp = "/^[A-Za-z .'-]+$/";
    	if(!preg_match($string_exp,$name)) {
    		$error_message .= 'The Name you entered does not appear to be valid.<br />';
    	}
    	
    	if(strlen($photocode) < 2) {
    		$error_message .= 'Please enter a Photo Code.<br />';
    	}
    	if(strlen($comments) < 2) {
    		$error_message .= 'Do you have nother to sq, No Comments?<br />';
    	}
    	if(strlen($error_message) > 0) {
    		died($error_message);
    	}
    You can edit the error message and/or the test (it currently only requires that the photocode be at least 2 characters long) to suit.

    If the field is not required, Do Not add it.

    I also noticed that the test for comments error message is probably a typo. It should probably be:

    Code:
    	if(strlen($comments) < 2) {
    		$error_message .= 'Do you have nothing to say, No Comments?<br />';
    	}
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Nov 2011
    Location
    Cider Region
    Posts
    1,132
    Thanks
    158
    Thanked 3 Times in 3 Posts

    Default

    I have done all the above but dont get the field shown in my email.

    Here is the page.
    http://www.ianparsons.info/email_copy%281%29.htm
    If you complete i will post a screen shot.

  8. #8
    Join Date
    Nov 2011
    Location
    Cider Region
    Posts
    1,132
    Thanks
    158
    Thanked 3 Times in 3 Posts

    Default

    Here are the 2 files if you would not mind just having a look at the text but i am sure i did it correct.

  9. #9
    Join Date
    Nov 2011
    Location
    Cider Region
    Posts
    1,132
    Thanks
    158
    Thanked 3 Times in 3 Posts

    Default

    I have also noticed that even if i leave the new field blank i do not get the message to advise me that i must type text in that new field.
    I have tried the same test like not entering my name but i get the message ok,also with the email the message pops up.
    No message pops up by leaving the photocode field empty and email is sent ??

    Strange.

  10. #10
    Join Date
    Nov 2011
    Location
    Cider Region
    Posts
    1,132
    Thanks
    158
    Thanked 3 Times in 3 Posts

    Default

    I now have it sorted.
    As the file i sent you was renamed copy at the end it did not work,removing copy then got it going.

    Thanks

Bookmarks

Posting Permissions

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