enable reCAPTCHA on contact form on joomla article

  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1241
  • Loc: Sydney

Post 3+ Months Ago

I am working on a joomla site for work and i just made a simple contact form in a joomla article, nice and simple but i am a little stuck on how i can apply the reCAPCHA form to this contact page. Now i have signed up and got my public and private keys and enabled in the CP reCAPTCHA function which is more for inside the web site functions but i don't think that will apply to the forum that sits on it's own.

if you take a quick look i am sure you can recognize the code that is everywhere but it works so why not use it. My question is, what am i to look for when applying this anti bot function to this stand alone form. just need some hints on what to change and figure it out from there.

html form
Code: [ Select ]
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td width="1%"> </td>
<td width="64%"> </td>
<td width="13%"> </td>
<td width="22%"> </td>
</tr>
<tr>
<td> </td>
<td>
<div align="center"><form action="http://www.timberprices.com.au/phpmail.php" method="post" name="htmlform">
<table style="width: 450px;">
<tbody>
<tr>
<td valign="top" width="185"><label for="first_name">First Name *</label></td>
<td valign="top" width="212"><input type="text" name="first_name" size="30" maxlength="50" /></td>
</tr>
<tr>
<td valign="top"><label for="last_name">Last Name *</label></td>
<td valign="top"><input type="text" name="last_name" size="30" maxlength="50" /></td>
</tr>
<tr>
<td valign="top"><label for="email">Email Address *</label></td>
<td valign="top"><input type="text" name="email" size="30" maxlength="80" /></td>
</tr>
<tr>
<td valign="top"><label for="telephone">Telephone Number</label></td>
<td valign="top"><input type="text" name="telephone" size="30" maxlength="30" /></td>
</tr>
<tr>
<td valign="top"><label for="comments">Comments *</label></td>
<td valign="top"><textarea name="comments" rows="6" cols="25"></textarea></td>
</tr>
<tr>
<td style="text-align: center;" colspan="2"><input type="submit" value="Submit" /></td>
</tr>
</tbody>
</table>
</form></div>
</td>
<td colspan="2">
<div align="center">{google_map}master woodturning{/google_map}</div>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<div align="center">
<h4>Office Hours</h4>
</div>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<div align="center">
<h4>7am till 5pm Monday To Friday</h4>
</div>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<div align="center">
<h4>Closed on Weekends</h4>
</div>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<h4> </h4>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<div align="center">
<h4>Sales: (02) 9829 5000</h4>
</div>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<div align="center">
<h4>Fax: (02) 9829 5100</h4>
</div>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<div align="center">
<h4>Address: 37 Lancaster Street, Ingleburn NSW 2565</h4>
</div>
</td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>
<h4> </h4>
</td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
  1. <table border="0" cellspacing="0" cellpadding="0" align="center">
  2. <tbody>
  3. <tr>
  4. <td width="1%"> </td>
  5. <td width="64%"> </td>
  6. <td width="13%"> </td>
  7. <td width="22%"> </td>
  8. </tr>
  9. <tr>
  10. <td> </td>
  11. <td>
  12. <div align="center"><form action="http://www.timberprices.com.au/phpmail.php" method="post" name="htmlform">
  13. <table style="width: 450px;">
  14. <tbody>
  15. <tr>
  16. <td valign="top" width="185"><label for="first_name">First Name *</label></td>
  17. <td valign="top" width="212"><input type="text" name="first_name" size="30" maxlength="50" /></td>
  18. </tr>
  19. <tr>
  20. <td valign="top"><label for="last_name">Last Name *</label></td>
  21. <td valign="top"><input type="text" name="last_name" size="30" maxlength="50" /></td>
  22. </tr>
  23. <tr>
  24. <td valign="top"><label for="email">Email Address *</label></td>
  25. <td valign="top"><input type="text" name="email" size="30" maxlength="80" /></td>
  26. </tr>
  27. <tr>
  28. <td valign="top"><label for="telephone">Telephone Number</label></td>
  29. <td valign="top"><input type="text" name="telephone" size="30" maxlength="30" /></td>
  30. </tr>
  31. <tr>
  32. <td valign="top"><label for="comments">Comments *</label></td>
  33. <td valign="top"><textarea name="comments" rows="6" cols="25"></textarea></td>
  34. </tr>
  35. <tr>
  36. <td style="text-align: center;" colspan="2"><input type="submit" value="Submit" /></td>
  37. </tr>
  38. </tbody>
  39. </table>
  40. </form></div>
  41. </td>
  42. <td colspan="2">
  43. <div align="center">{google_map}master woodturning{/google_map}</div>
  44. </td>
  45. </tr>
  46. <tr>
  47. <td> </td>
  48. <td> </td>
  49. <td> </td>
  50. <td> </td>
  51. </tr>
  52. <tr>
  53. <td> </td>
  54. <td>
  55. <div align="center">
  56. <h4>Office Hours</h4>
  57. </div>
  58. </td>
  59. <td> </td>
  60. <td> </td>
  61. </tr>
  62. <tr>
  63. <td> </td>
  64. <td>
  65. <div align="center">
  66. <h4>7am till 5pm Monday To Friday</h4>
  67. </div>
  68. </td>
  69. <td> </td>
  70. <td> </td>
  71. </tr>
  72. <tr>
  73. <td> </td>
  74. <td>
  75. <div align="center">
  76. <h4>Closed on Weekends</h4>
  77. </div>
  78. </td>
  79. <td> </td>
  80. <td> </td>
  81. </tr>
  82. <tr>
  83. <td> </td>
  84. <td>
  85. <h4> </h4>
  86. </td>
  87. <td> </td>
  88. <td> </td>
  89. </tr>
  90. <tr>
  91. <td> </td>
  92. <td>
  93. <div align="center">
  94. <h4>Sales: (02) 9829 5000</h4>
  95. </div>
  96. </td>
  97. <td> </td>
  98. <td> </td>
  99. </tr>
  100. <tr>
  101. <td> </td>
  102. <td>
  103. <div align="center">
  104. <h4>Fax: (02) 9829 5100</h4>
  105. </div>
  106. </td>
  107. <td> </td>
  108. <td> </td>
  109. </tr>
  110. <tr>
  111. <td> </td>
  112. <td> </td>
  113. <td> </td>
  114. <td> </td>
  115. </tr>
  116. <tr>
  117. <td> </td>
  118. <td>
  119. <div align="center">
  120. <h4>Address: 37 Lancaster Street, Ingleburn NSW 2565</h4>
  121. </div>
  122. </td>
  123. <td> </td>
  124. <td> </td>
  125. </tr>
  126. <tr>
  127. <td> </td>
  128. <td>
  129. <h4> </h4>
  130. </td>
  131. <td> </td>
  132. <td> </td>
  133. </tr>
  134. </tbody>
  135. </table>


php processing
Code: [ Select ]
<?php
if(isset($_POST['email'])) {
  
  // CHANGE THE TWO LINES BELOW
  $email_to = "sales@masterwoodturning.com.au";
  
  $email_subject = "Timber Prices | Contact form";
  
  
  function died($error) {
    // your error code can go here
    echo "We are very sorry, but there were error(s) found with the form you submitted. ";
    echo "These errors appear below.<br /><br />";
    echo $error."<br /><br />";
    echo "Please go back and fix these errors.<br /><br />";
    die();
  }
  
  // validation expected data exists
  if(!isset($_POST['first_name']) ||
    !isset($_POST['last_name']) ||
    !isset($_POST['email']) ||
    !isset($_POST['telephone']) ||
    !isset($_POST['comments'])) {
    died('We are sorry, but there appears to be a problem with the form you submitted.');   
  }
  
  $first_name = $_POST['first_name']; // required
  $last_name = $_POST['last_name']; // required
  $email_from = $_POST['email']; // required
  $telephone = $_POST['telephone']; // not required
  $comments = $_POST['comments']; // required
  
  $error_message = "";
  $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,$first_name)) {
  $error_message .= 'The First Name you entered does not appear to be valid.<br />';
 }
 if(!preg_match($string_exp,$last_name)) {
  $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
 }
 if(strlen($comments) < 2) {
  $error_message .= 'The Comments you entered do not appear to be valid.<br />';
 }
 if(strlen($error_message) > 0) {
  died($error_message);
 }
  $email_message = "Form details below.\n\n";
  
  function clean_string($string) {
   $bad = array("content-type","bcc:","to:","cc:","href");
   return str_replace($bad,"",$string);
  }
  
  $email_message .= "First Name: ".clean_string($first_name)."\n";
  $email_message .= "Last Name: ".clean_string($last_name)."\n";
  $email_message .= "Email: ".clean_string($email_from)."\n";
  $email_message .= "Telephone: ".clean_string($telephone)."\n";
  $email_message .= "Comments: ".clean_string($comments)."\n";
  
  
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>


<!-- place your own success html below -->
<body bgcolor="#dcd0bb">
<div align="center"><img src="http://timberprices.com.au/images/860x171_site_logo.png"</img></div>
<div align="center" >
<div align="center"><p>Thank you for contacting us. We will be in touch with you very soon. </p></div>
<div align="center"><p>If you have any questions please call us (02) 9829 5000</p>
<script type="text/javascript" align="center">
<!--
function Redirect()
{
  window.location="http://www.timberprices.com.au";
}

document.write("You will be redirected to main page in 5 sec.");
setTimeout('Redirect()', 5000);
//-->
</script>
</div>
</body>

<?php
}
die();
?>
  1. <?php
  2. if(isset($_POST['email'])) {
  3.   
  4.   // CHANGE THE TWO LINES BELOW
  5.   $email_to = "sales@masterwoodturning.com.au";
  6.   
  7.   $email_subject = "Timber Prices | Contact form";
  8.   
  9.   
  10.   function died($error) {
  11.     // your error code can go here
  12.     echo "We are very sorry, but there were error(s) found with the form you submitted. ";
  13.     echo "These errors appear below.<br /><br />";
  14.     echo $error."<br /><br />";
  15.     echo "Please go back and fix these errors.<br /><br />";
  16.     die();
  17.   }
  18.   
  19.   // validation expected data exists
  20.   if(!isset($_POST['first_name']) ||
  21.     !isset($_POST['last_name']) ||
  22.     !isset($_POST['email']) ||
  23.     !isset($_POST['telephone']) ||
  24.     !isset($_POST['comments'])) {
  25.     died('We are sorry, but there appears to be a problem with the form you submitted.');   
  26.   }
  27.   
  28.   $first_name = $_POST['first_name']; // required
  29.   $last_name = $_POST['last_name']; // required
  30.   $email_from = $_POST['email']; // required
  31.   $telephone = $_POST['telephone']; // not required
  32.   $comments = $_POST['comments']; // required
  33.   
  34.   $error_message = "";
  35.   $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  36.  if(!preg_match($email_exp,$email_from)) {
  37.   $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  38.  }
  39.   $string_exp = "/^[A-Za-z .'-]+$/";
  40.  if(!preg_match($string_exp,$first_name)) {
  41.   $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  42.  }
  43.  if(!preg_match($string_exp,$last_name)) {
  44.   $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  45.  }
  46.  if(strlen($comments) < 2) {
  47.   $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  48.  }
  49.  if(strlen($error_message) > 0) {
  50.   died($error_message);
  51.  }
  52.   $email_message = "Form details below.\n\n";
  53.   
  54.   function clean_string($string) {
  55.    $bad = array("content-type","bcc:","to:","cc:","href");
  56.    return str_replace($bad,"",$string);
  57.   }
  58.   
  59.   $email_message .= "First Name: ".clean_string($first_name)."\n";
  60.   $email_message .= "Last Name: ".clean_string($last_name)."\n";
  61.   $email_message .= "Email: ".clean_string($email_from)."\n";
  62.   $email_message .= "Telephone: ".clean_string($telephone)."\n";
  63.   $email_message .= "Comments: ".clean_string($comments)."\n";
  64.   
  65.   
  66. // create email headers
  67. $headers = 'From: '.$email_from."\r\n".
  68. 'Reply-To: '.$email_from."\r\n" .
  69. 'X-Mailer: PHP/' . phpversion();
  70. @mail($email_to, $email_subject, $email_message, $headers);
  71. ?>
  72. <!-- place your own success html below -->
  73. <body bgcolor="#dcd0bb">
  74. <div align="center"><img src="http://timberprices.com.au/images/860x171_site_logo.png"</img></div>
  75. <div align="center" >
  76. <div align="center"><p>Thank you for contacting us. We will be in touch with you very soon. </p></div>
  77. <div align="center"><p>If you have any questions please call us (02) 9829 5000</p>
  78. <script type="text/javascript" align="center">
  79. <!--
  80. function Redirect()
  81. {
  82.   window.location="http://www.timberprices.com.au";
  83. }
  84. document.write("You will be redirected to main page in 5 sec.");
  85. setTimeout('Redirect()', 5000);
  86. //-->
  87. </script>
  88. </div>
  89. </body>
  90. <?php
  91. }
  92. die();
  93. ?>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: expedien_123 and 44 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.