Advertisement
Guest User

CAPTCHA

a guest
Aug 27th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.09 KB | None | 0 0
  1. <?php
  2. // Set email variables
  3. $email_to = 'es.com.au';
  4. $email_subject = 'Form submission';
  5.  
  6. // Set required fields
  7. $required_fields = array('fullname','email','comment','phone','street','town','reCAPTCHA');
  8.  
  9. // set error messages
  10. $error_messages = array(
  11. 'fullname' => 'Please enter in a Name to proceed.',
  12. 'email' => 'Please enter in a valid Email Address',
  13. 'comment' => 'Please enter your Message to continue.',
  14. 'phone' => 'Please enter in a valid phone number',
  15. 'street' => 'Please enter in your Street Address',
  16. 'town' => 'please enter in your Town',
  17. 'reCAPTCHA' => 'Please enter in the reCaptcha correctly',
  18. );
  19.  
  20. // Set form status
  21. $form_complete = FALSE;
  22.  
  23. // configure validation array
  24. $validation = array();
  25.  
  26. // check form submittal
  27. if(!empty($_POST)) {
  28. // Sanitise POST array
  29. foreach($_POST as $key => $value) $_POST[$key] = remove_email_injection(trim($value));
  30.  
  31. // Loop into required fields and make sure they match our needs
  32. foreach($required_fields as $field) {
  33. // the field has been submitted?
  34. if(!array_key_exists($field, $_POST)) array_push($validation, $field);
  35.  
  36. // check there is information in the field?
  37. if($_POST[$field] == '') array_push($validation, $field);
  38.  
  39. // validate the email address supplied
  40. if($field == 'email') if(!validate_email_address($_POST[$field])) array_push($validation, $field);
  41. }
  42.  
  43. // basic validation result
  44. if(count($validation) == 0) {
  45. // Prepare our content string
  46. $email_content = 'New Website Comment: ' . "\n\n";
  47.  
  48. // simple email content
  49. foreach($_POST as $key => $value) {
  50. if($key != 'submit') $email_content .= $key . ': ' . $value . "\n";
  51. }
  52.  
  53. // if validation passed ok then send the email
  54. mail($email_to, $email_subject, $email_content);
  55.  
  56. // Update form switch
  57. $form_complete = TRUE;
  58. }
  59. }
  60.  
  61. function validate_email_address($email = FALSE) {
  62. return (preg_match('/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i', $email))? TRUE : FALSE;
  63.  
  64. }
  65.  
  66.  
  67.  
  68. function remove_email_injection($field = FALSE) {
  69. return (str_ireplace(array("\r", "\n", "%0a", "%0d", "Content-Type:", "bcc:","to:","cc:"), '', $field));
  70. }
  71.  
  72. ?>
  73. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  74. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  75. <head>
  76. <title>Contact Form</title>
  77. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  78.  
  79. <link href="contact/css/contactform.css" rel="stylesheet" type="text/css" />
  80. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.0/mootools-yui-compressed.js"></script>
  81. <script type="text/javascript" src="content/validation/validation.js"></script>
  82. </script>
  83.  
  84.  
  85. <script type="text/javascript">
  86. var nameError = '<?php echo $error_messages['fullname']; ?>';
  87. var streetError = '<?php echo $error_messages['street']; ?>';
  88. var townError = '<?php echo $error_messages['town']; ?>';
  89. var emailError = '<?php echo $error_messages['email']; ?>';
  90. var commentError = '<?php echo $error_messages['comment']; ?>';
  91. var phoneError = '<?php echo $error_messages['phone']; ?>';
  92. var reCAPTCHAError ='<?php echo $error_message['reCAPTCHA']; ?>';
  93.  
  94. function MM_preloadImages() { //v3.0
  95. var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  96. var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  97. if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
  98. }
  99. </script>
  100. <link href="default.css" rel="stylesheet" type="text/css" />
  101.  
  102. </head>
  103.  
  104. <body onLoad="MM_preloadImages('content/images/x.png')">
  105.  
  106. <div id="header">
  107. <div id="menu">
  108. <ul>
  109. <li class="active"><a href="http://.tk/#">Home</a></li>
  110. <li class="active"><a href="http://.tk/contact.php">Contact Form</a></li>
  111. <li><a href="http:///.php">FileZilla</a></li>
  112. <li><a href="http://.tk/Captchaguide.php">CAPTCHA</a></li>
  113. <li><a href="#">Link 3</a></li>
  114. <li><a href="#">Link 4</a></li>
  115. </ul>
  116. </div>
  117. <div id="logo">
  118. <h1><a href="#">y</a></h1>
  119. <h2><a href="#">e</a></h2>
  120. </div>
  121. </div>
  122. <!-- end header -->
  123.  
  124. <div id="formWrap">
  125. <h2>We Appreciate Your Feedback</h2>
  126. <div id="form">
  127. <?php if($form_complete === FALSE): ?>
  128. <form action="contact.php" method="post" id="comments_form">
  129.  
  130. <div class="row">
  131. <div class ="label">Your Name</div> <!-- end .label -->
  132. <div class = "input">
  133. <input type="text" id="fullname" class="detail" name="fullname" value="<?php echo isset($_POST['fullname'])? $_POST['fullname'] : ''; ?>" />
  134. <?php if(in_array('fullname', $validation)): ?><span class="error"><?php echo $error_messages['fullname']; ?></span><?php endif; ?>
  135.  
  136. </div><!-- end .input -->
  137. <div class="context">e.g John Smith</div><!-- end .context -->
  138. </div><!-- end .row -->
  139.  
  140. <div class="row">
  141. <div class ="label">Street Address</div> <!-- end .label -->
  142. <div class = "input">
  143. <input type="text" id="street" class="detail" name="street" value="<?php echo isset($_POST['street'])? $_POST['street'] : ''; ?>" />
  144. <?php if(in_array('street', $validation)): ?><span class="error"><?php echo $error_messages['street']; ?></span><?php endif; ?>
  145. </div><!-- end .input -->
  146. <div class="context"> We will not use this information for commercial purposes</div>
  147. </div><!-- end .row -->
  148.  
  149. <div class="row">
  150. <div class ="label">Town</div> <!-- end .label -->
  151. <div class = "input">
  152. <input type="text" id="town" class="detail" name="town" value="<?php echo isset($_POST['town'])? $_POST['town'] : ''; ?>" />
  153. <?php if(in_array('town', $validation)): ?><span class="error"><?php echo $error_messages['town']; ?></span><?php endif; ?>
  154. </div><!-- end .input -->
  155. <div class="context"> We will not use this information for commercial purposes</div>
  156. </div><!-- end .row -->
  157.  
  158. <div class="row">
  159. <div class ="label">Phone Number</div> <!-- end .label -->
  160. <div class = "input">
  161. <input type="text" id="phone" class="detail" maxlength="10" name="phone" value="<?php echo isset($_POST['phone'])? $_POST['phone'] : ''; ?>" />
  162. <?php if(in_array('phone', $validation)): ?><span class="error"><?php echo $error_messages['phone']; ?></span><?php endif; ?>
  163.  
  164. </div><!-- end .input -->
  165. <div class="context">We will not share your Phone Number</div>
  166. </div><!-- end .row -->
  167.  
  168.  
  169. <div class="row">
  170. <div class ="label">Your Email Address</div> <!-- end .label -->
  171. <div class = "input">
  172. <input type="text" id="email" class="detail" name="email" value="<?php echo isset($_POST['email'])? $_POST['email'] : ''; ?>" />
  173. <?php if(in_array('email', $validation)): ?><span class="error"><?php echo $error_messages['email']; ?></span><?php endif; ?>
  174.  
  175. </div><!-- end .input -->
  176. <div class="context">We will not share you email with anyone or spam.</div>
  177. </div><!-- end .row -->
  178.  
  179. <div class="row">
  180. <div class ="label">Your Message</div> <!-- end .label -->
  181. <div class = "input">
  182. <textarea id= "comment" name="comment" class="mess"><?php echo isset($_POST['comment'])? $_POST['comment'] : ''; ?></textarea>
  183. <?php if(in_array('comment', $validation)): ?><span class="error"><?php echo $error_messages['comment']; ?></span><?php endif; ?>
  184. <?php require_once('recaptchalib.php');
  185. $publickey = "6LcKbeUSAAAAAPebMsf38ZsbLs1pkkj-W6JRoxaS"; // you got this from the signup page
  186. echo recaptcha_get_html($publickey);
  187. ?>
  188. <?php
  189.  
  190. if (isset($_POST['submit'])){
  191.  
  192. require_once('recaptchalib.php');
  193. $privatekey = "6LcKbeUSAAAAABoenA5RB81vs59VIWIQvkU41vHE";
  194. $resp = recaptcha_check_answer ($privatekey,
  195. $_SERVER["REMOTE_ADDR"],
  196. $_POST["recaptcha_challenge_field"],
  197. $_POST["recaptcha_response_field"]);
  198.  
  199. if (!$resp->is_valid) {
  200. // What happens when the CAPTCHA was entered incorrectly
  201. }
  202. else {// What happens when it was successful.};
  203. }
  204. ?>
  205. <!--Error Checking -->
  206.  
  207.  
  208. </div><!-- end .input -->
  209. </div><!-- end .row -->
  210. <!-- submist button -->
  211. <div class="submit">
  212. <input name="submit" id="submit" type="submit" value="Submit" />
  213. <?php else:?>
  214. <p style="font-size:35px; font-family:Arial, Helvetica, sans-serif; color:#255E67; text-align:center;">Thank you for your Message!</p>
  215.  
  216.  
  217.  
  218. <script type="text/javascript">
  219. setTimeout('ourRedirect()', 5000)
  220. function ourRedirect(){
  221. location.href='contact.php'
  222. }
  223.  
  224.  
  225. </script>
  226.  
  227. <script language="javascript">
  228.  
  229. var time_left = 5;
  230. var cinterval;
  231.  
  232. function time_dec(){
  233. time_left--;
  234. document.getElementById('countdown').innerHTML = time_left;
  235. if(time_left == 0){
  236. clearInterval(cinterval);
  237. }
  238. }
  239.  
  240. cinterval = setInterval('time_dec()', 1000);
  241.  
  242. </script>
  243.  
  244. <p style="font-size:20px; font-family:Arial, Helvetica, sans-serif; color:#000; font-weight:bold; text-align:center;13px;">Redirecting In <span id="countdown">5</span>.</p>
  245.  
  246. <?php endif; ?>
  247. </div><!-- End .submit -->
  248. </form>
  249.  
  250. <!-- end .context -->
  251. </div><!-- end .row -->
  252.  
  253. </div>
  254. <!-- end #form-->
  255. </div>
  256. </body>
  257. <!-- end page -->
  258. <div id="footer">
  259. <p id="legal">&copy;2013 All Rights Reserved.</p>
  260. </div>
  261. </html>
  262. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement