Advertisement
Guest User

rederror

a guest
Nov 7th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.07 KB | None | 0 0
  1. <div class="row">
  2. <div class="large-9 columns">
  3. <div id="contact">
  4. <section class="formleft">
  5. <h3>Hello, let's talk!</h3>
  6. <?php
  7.  
  8.  
  9. //If the form is submitted:
  10. if(isset($_POST['submitted'])) {
  11.  
  12. //load recaptcha file
  13. require_once('captcha/recaptchalib.php');
  14.  
  15. //enter your recaptcha private key
  16. $privatekey = "recaptcha private key";
  17.  
  18. //check recaptcha fields
  19. $resp = recaptcha_check_answer ($privatekey,
  20. $_SERVER["REMOTE_ADDR"],
  21. $_POST["recaptcha_challenge_field"],
  22. $_POST["recaptcha_response_field"]);
  23.  
  24.  
  25. //Check to see if the invisible field has been filled in
  26. if(trim($_POST['checking']) !== '') {
  27. $blindError = true;
  28. } else {
  29.  
  30. //Check to make sure that a contact name has been entered
  31. $authorName = (filter_var($_POST['formAuthor'], FILTER_SANITIZE_STRING));
  32. if ($authorName == ""){
  33. $authorError = true;
  34. $hasError = true;
  35. }else{
  36. $formAuthor = $authorName;
  37. };
  38.  
  39.  
  40. //Check to make sure sure that a valid email address is submitted
  41. $authorEmail = (filter_var($_POST['formEmail'], FILTER_SANITIZE_EMAIL));
  42. if (!(filter_var($authorEmail, FILTER_VALIDATE_EMAIL))){
  43. $emailError = true;
  44. $hasError = true;
  45. } else{
  46. $formEmail = $authorEmail;
  47. };
  48.  
  49. //Check to make sure the subject of the message has been entered
  50. $msgSubject = (filter_var($_POST['formSubject'], FILTER_SANITIZE_STRING));
  51. if ($msgSubject == ""){
  52. $subjectError = true;
  53. $hasError = true;
  54. }else{
  55. $formSubject = $msgSubject;
  56. };
  57.  
  58. //Check to make sure content has been entered
  59. $msgContent = (filter_var($_POST['formContent'], FILTER_SANITIZE_STRING));
  60. if ($msgContent == ""){
  61. $commentError = true;
  62. $hasError = true;
  63. }else{
  64. $formContent = $msgContent;
  65. };
  66.  
  67. // if all the fields have been entered correctly and there are no recaptcha errors build an email message
  68. if (($resp->is_valid) && (!isset($hasError))) {
  69. $emailTo = 'acer@aceralhashimi.info'; // here you must enter the email address you want the email sent to
  70. $subject = 'A new message from: ' . $formAuthor . ' | ' . $formSubject; // This is how the subject of the email will look like
  71. $body = "Email: $formEmail \n\nContent: $formContent \n\n$formAuthor"; // This is the body of the email
  72. $headers = 'From: <'.$formEmail.'>' . "\r\n" . 'Reply-To: ' . $formEmail . "\r\n" . 'Return-Path: ' . $formEmail; // Email headers
  73.  
  74. //send email
  75. mail($emailTo, $subject, $body, $headers);
  76.  
  77. // set a variable that confirms that an email has been sent
  78. $emailSent = true;
  79. }
  80.  
  81. // if there are errors in captcha fields set an error variable
  82. if (!($resp->is_valid)){
  83. $captchaErrorMsg = true;
  84. }
  85. }
  86. } ?>
  87.  
  88. <?php // if the page the variable "email sent" is set to true show confirmation instead of the form ?>
  89. <?php if(isset($emailSent) && $emailSent == true) { ?>
  90. <p>
  91. Your email was successfully sent. I check my inbox all the time, so I should be in touch soon.
  92. </p>
  93. <?php } else { ?>
  94. <?php // if there are errors in the form show a message ?>
  95. <?php if(isset($hasError) || isset($blindError)) { ?>
  96. <p>There was an error submitting the form. Please check all the marked fields.</p>
  97. <?php } ?>
  98. <?php // if there are recaptcha errors show a message ?>
  99. <?php if ($captchaErrorMsg){ ?>
  100. <p>Captcha error. Please, type the check-words again.</p>
  101. <?php } ?>
  102. <?php
  103. // here, you set what the recaptcha module should look like
  104. // possible options: red, white, blackglass and clean
  105. // more infor on customisation can be found here: http://code.google.com/intl/pl-PL/apis/recaptcha/docs/customization.html
  106. ?>
  107. <script type="text/javascript">
  108. var RecaptchaOptions = {
  109. theme : 'clean'
  110. };
  111. </script>
  112. <?php
  113. // this is where the form starts
  114. // action attribute should contain url of the page with this form
  115. // more on that you can read here: http://www.w3schools.com/TAGS/att_form_action.asp
  116. ?>
  117. <form id="contactForm" action="" method="post">
  118. <div id="singleParagraphInputs">
  119. <div>
  120. <label for="formAuthor">
  121. Name
  122. </label>
  123. <input class="requiredField <?php if($authorError) { echo 'formError'; } ?>" type="text" name="formAuthor" id="formAuthor" value="<?php if(isset($_POST['formAuthor'])) echo $_POST['formAuthor'];?>" size="40" />
  124. </div>
  125. <div>
  126. <label for="formEmail">
  127. Email
  128. </label>
  129. <input class="requiredField <?php if($emailError) { echo 'formError'; } ?>" type="text" name="formEmail" id="formEmail" value="<?php if(isset($_POST['formEmail'])) echo $_POST['formEmail'];?>" size="40" />
  130. </div>
  131. <div>
  132. <label for="formSubject">
  133. Subject
  134. </label>
  135. <input class="requiredField <?php if($subjectError) { echo 'formError'; } ?>" type="text" name="formSubject" id="formSubject" value="<?php if(isset($_POST['formSubject'])) echo $_POST['formSubject'];?>" size="40" />
  136. </div>
  137. </div>
  138. <div id="commentTxt">
  139. <label for="formContent">
  140. Message
  141. </label>
  142. <textarea class="requiredField <?php if($commentError) { echo 'formError'; } ?>" id="formContent" name="formContent" cols="40" rows="5"><?php if(isset($_POST['formContent'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['formContent']); } else { echo $_POST['formContent']; } } ?></textarea>
  143. <?php
  144. // this field is visible only to robots and screenreaders
  145. // if it is filled in it means that a human hasn't submitted this form thus it will be rejected
  146. ?><br/>
  147. <div id="screenReader">
  148. <input type="text" name="checking" id="checking" value="<?php if(isset($_POST['checking'])) echo $_POST['checking'];?>" style="display:none;"/>
  149. </div>
  150. </div>
  151. <?php
  152. // load recaptcha file
  153. require_once('captcha/recaptchalib.php');
  154. // enter your public key
  155. $publickey = "public key";
  156. // display recaptcha test fields
  157. echo recaptcha_get_html($publickey);
  158. ?>
  159. <input type="hidden" name="submitted" id="submitted" value="true" />
  160. <?php // submit button ?>
  161. <input type="submit" value="Send" tabindex="5" id="submit" class="button1" name="submit">
  162. </form>
  163. <?php } ?>
  164. </div>
  165. </section>
  166. </div>
  167. </div>
  168. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement