5 Replies - 1146 Views - Last Post: 14 July 2014 - 01:58 PM Rate Topic: -----

#1 Husbarn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-July 14

Installing recaptcha to my inquiry form

Posted 11 July 2014 - 11:30 AM

First of all I want to say hi to everyone, because I'm new here and this is my first post. I need some help with my code and would be nice to receive that help. :)/>

I want to install recaptcha to my inquiry form and I need some help with the code.

I'm talking about this recaptcha - https://developers.g.../docs/php?hl=de

I'm using Wordpress (with my own hosting).

Example page how that "send inquiry" button looks like - http://www.camarocar...evrolet-camaro/

I already added that "recaptchalib.php" file to my theme files and I can access it from my wp panel>editor. However, I don't need to touch it, because I just need to have it there and I need to add that code (in that link, given below "quick start") where my inquiry form is.

As I understand, I need to add this code
require_once('recaptchalib.php');
  $publickey = "your_public_key"; // you got this from the signup page
  echo recaptcha_get_html($publickey);
to the file where my inquiry form is.

I've found that file and here is the code for that inquiry form (this is the whole code from .php file:
<?php
if($_POST)
{
	$yourname = $_POST['inq_name'];
	$youremail = $_POST['inq_email'];
	$inq_phone = $_POST['inq_phone'];
	$frnd_comments = $_POST['inq_msg'];
	$pid = $_POST['pid'];

	$post_title = '<a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a>'; 
	$to_name = get_post_meta($post->ID,'name',true);
	$to_email = get_post_meta($post->ID,'email',true);
	if($to_email=='')
	{
		$to_email = get_option('admin_email');	
	}
	///////Inquiry EMAIL START//////
	global $upload_folder_path;
	$clientdestinationfile =   get_bloginfo( 'template_directory', 'false' )."/library/notification/send_inquiry.txt";
	$message1 = file_get_contents($clientdestinationfile);
	$filecontent_arr1 = explode('[SUBJECT-STR]',$message1);
	$filecontent_arr2 = explode('[SUBJECT-END]',$filecontent_arr1[1]);
	$subject = $filecontent_arr2[0]. __(' for ').'"'.$post->post_title.'"';
	
	$client_message = $filecontent_arr2[1];
	$yourname_link = __('<br>From : ').$yourname.__('<br>Phone : ').$inq_phone.'<br><br>Sent from - <b><a href="'.get_option('siteurl').'">'.get_option('blogname').'</a></b>.';
	/////////////customer email//////////////
	$search_array = array('[#$to_name#]','[#$post_title#]','[#$frnd_subject#]','[#$frnd_comments#]','[#$your_name#]');
	$replace_array = array($to_name,$post_title,$frnd_subject,nl2br($frnd_comments),$yourname_link);
	$client_message = str_replace($search_array,$replace_array,$client_message);
/*	echo "From : $youremail  Name : $yourname <br>";
	echo "To : $to_email  Name : $to_name <br>";
	echo "Subject $subject <br>";
	echo "$client_message";
	exit;*/
	if($to_email)
	{
		sendEmail($youremail,$yourname,$to_email,$to_name,$subject,$client_message,$extra='');
	}
	//////Inquiry EMAIL END////////	
	$url = get_permalink($post->ID);
	if(strstr($url,'?'))
	  {
		  $url = $url."&send_inquiry=success";
	  }else
	  {
			$url = $url."?send_inquiry=success";			  
	  }
	wp_redirect($url);
}
?>	


So, I need that captcha to this inquiry form. If you go to that URL above (camaro site) and click on "send inquiry" (red button on the right side), an inquiry form appears. That code above is of that form and I need to add this recaptcha to this form, so that this captcha must be resolved before people can click on "send" button or at least if that captcha isn't resolved correctly, they won't be able to send this form.

Any ideas how to make this work?

Is This A Good Question/Topic? 0
  • +

Replies To: Installing recaptcha to my inquiry form

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5226
  • View blog
  • Posts: 14,005
  • Joined: 18-April 07

Re: Installing recaptcha to my inquiry form

Posted 11 July 2014 - 12:14 PM

That code file you are showing there is NOT the file you have to put that recapchalib.php code in. That is the code that processes your form. You have to find the page that actually has the form HTML on it. So you are looking for a file that has the line "<form method='post' action=''>" etc etc. The second part of this code (as pointed out on the google page) is to be put in that code you show there. Probably right above the line $yourname = $_POST['inq_name'];.

:)
Was This Post Helpful? 0
  • +
  • -

#3 Husbarn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-July 14

Re: Installing recaptcha to my inquiry form

Posted 11 July 2014 - 12:35 PM

I understand that I have that recapchalib.php file to put in in my folder where all .php files are. I know that I don't need to put it in that code I've provided in my first post. :)

I've tried to add that code (as pointed out on the google page) below similar line, just not below name line, but below comment line, but like this captcha isn't showing at all. It shows when I type everything (in submit inquiry form) and when i click send, on the next page I can see captcha, but like this, Inquiry already is sent, so no good to me. I need it to show up in that form.

Also, code given above is not from recapchalib.php file, it is from inquiry form .php file.

This post has been edited by andrewsw: 14 July 2014 - 01:59 PM
Reason for edit:: Removed previous quote

Was This Post Helpful? 0
  • +
  • -

#4 Husbarn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-July 14

Re: Installing recaptcha to my inquiry form

Posted 12 July 2014 - 05:44 AM

Actually the popup form code is this
<form method="post" name="agt_mail_agent" id="agt_mail_agent" action="<?php echo get_permalink($post->ID); ?>" >
  <input type="hidden" name="pid" id="agt_mail_agent_pid" value="<?php echo $post->ID;?>" />
  <input type="hidden" name="sendact" value="send_inqury" />
	<h3><?php echo SEND_INQUIRY;?> </h3>
    <p id="inquiry_send_success" class="sucess_msg" style="display:none;"></p>
	<div class="row  clearfix" ><label><?php _e('Your Name');?> :  <span>*</span></label><input name="inq_name" id="agt_mail_name" type="text"  /><span id="span_agt_mail_name"></span></div>
 	<div class="row  clearfix" ><label><?php _e('Email');?> :  <span>*</span></label><input name="inq_email" id="agt_mail_email" type="text"  /><span id="span_agt_mail_email"></span></div>
	<div class="row  clearfix" ><label><?php _e('Contact Info');?> :</label><input name="inq_phone" id="agt_mail_phone" type="text"  /></div>
	<div class="row  clearfix" ><label><?php _e('Comments');?> :  <span>*</span></label>
     <textarea name="inq_msg" id="agt_mail_msg" cols="" rows="" ><?php echo SEND_INQUIRY_SAMPLE_CONTENT;?></textarea>
     <span id="span_agt_mail_msg"></span>
    </div>
	<input name="Send" type="submit"  value="<?php _e('Send');?>" class="button clearfix" />
 </form>


That form above (in my first post) is the form where the data from the form is sent to.
Was This Post Helpful? 0
  • +
  • -

#5 Husbarn   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-July 14

Re: Installing recaptcha to my inquiry form

Posted 14 July 2014 - 01:56 PM

I am kind of a newbie in all this PHP stuff, but I know the basics. I need a little help (should be very easy for someone who knows PHP well).

I want to add captcha to my submission form, but not sure where to add validation code.

Here is the submission form code:

<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/library/js/inquiry_validation.js"></script>
			
<div id="basic-modal-content2" class="clearfix">
 <form method="post" name="agt_mail_agent" id="agt_mail_agent" action="<?php echo get_permalink($post->ID); ?>" >
  <input type="hidden" name="pid" id="agt_mail_agent_pid" value="<?php echo $post->ID;?>" />
  <input type="hidden" name="sendact" value="send_inqury" />
	<h3><?php echo SEND_INQUIRY;?> </h3>
    <p id="inquiry_send_success" class="sucess_msg" style="display:none;"></p>
	<div class="row  clearfix" ><label><?php _e('Your Name');?> :  <span>*</span></label><input name="inq_name" id="agt_mail_name" type="text"  /><span id="span_agt_mail_name"></span></div>
 	<div class="row  clearfix" ><label><?php _e('Email');?> :  <span>*</span></label><input name="inq_email" id="agt_mail_email" type="text"  /><span id="span_agt_mail_email"></span></div>
	<div class="row  clearfix" ><label><?php _e('Contact Info');?> :</label><input name="inq_phone" id="agt_mail_phone" type="text"  /></div>
	<div class="row  clearfix" ><label><?php _e('Comments');?> :  <span>*</span></label>
     <textarea name="inq_msg" id="agt_mail_msg" cols="" rows="" ><?php echo SEND_INQUIRY_SAMPLE_CONTENT;?></textarea>
     <span id="span_agt_mail_msg"></span>
    </div>
	<input name="Send" type="submit"  value="<?php _e('Send');?>" class="button clearfix" />
 </form>


As I understand I should open that "inquiry_validation.js" and edit it?

I want to add this captcha as found here - https://developers.g.../docs/php?hl=de

I know it is a simple work, but since I am a newbie in all this, I have some difficulties with it. Would be really nice if someone could help me with it. :)

All I need is a confirmation that I should edit that file I've mentioned above and what code I should add there. I have two API keys already, So I'll do that replacement by myself, I just would like to get codes that I need to add to my current form and that .js file.

Here's the code inside that .js file:

$(document).ready(function(){function u(){if($("#agt_mail_name").val()==""){t.addClass("error");n.text("Please Enter Your Name");n.addClass("message_error2");return false}else{t.removeClass("error");n.text("");n.removeClass("message_error2");return true}}function a(){var e=0;if($("#agt_mail_email").val()==""){e=1}else if($("#agt_mail_email").val()!=""){var t=$("#agt_mail_email").val();var n=/^[a-zA-Z0-9]+[a-zA-Z0-9_.-]+[a-zA-Z0-9_-][email protected][a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;if(n.test(t)){e=0}else{e=1}}if(e){r.addClass("error");i.text("Please Enter valid Email Address");i.addClass("message_error2");return false}else{r.removeClass("error");i.text("");i.removeClass("message_error");return true}}function f(){if($("#agt_mail_msg").val()==""){s.addClass("error");o.text("Please Enter Comments");o.addClass("message_error2");return false}else{s.removeClass("error");o.text("");o.removeClass("message_error2");return true}}function l(){document.getElementById("agt_mail_name").value="";document.getElementById("agt_mail_email").value="";document.getElementById("agt_mail_phone").value="";document.getElementById("agt_mail_msg").value=""}var e=$("#agt_mail_agent");var t=$("#agt_mail_name");var n=$("#span_agt_mail_name");var r=$("#agt_mail_email");var i=$("#span_agt_mail_email");var s=$("#agt_mail_msg");var o=$("#span_agt_mail_msg");t.blur(u);r.blur(a);s.blur(f);t.keyup(u);r.keyup(a);s.keyup(f);e.submit(function(){if(u()&a()&f()){return true}else{return false}})})

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is online

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6552
  • View blog
  • Posts: 26,562
  • Joined: 12-December 12

Re: Installing recaptcha to my inquiry form

Posted 14 July 2014 - 01:58 PM

Do not start a duplicate topic on the same question. Topics merged.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1