Guest User

Untitled

a guest
Apr 25th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. (document).ready(function($){
  2.  
  3. $.validator.addMethod("lettersonly", function(value, element) {
  4. return this.optional(element) || /^[a-zs]+$/i.test(value);
  5. }, "Only alphabetical characters");
  6.  
  7. $.validator.addMethod("phoneNum", function(value, element) {
  8. return this.optional(element) || /^[0-9-s]+$/i.test(value);
  9. }, "Phone number can only be number and dashes.");
  10.  
  11.  
  12. $("#contact-form").validate({
  13. rules: {
  14. name: {
  15. required:true,
  16. lettersonly: true
  17. },
  18. email: {
  19. required: true,
  20. email: true
  21. },
  22. phone: {
  23. phoneNum: true,
  24. },
  25. message: {
  26. required:true
  27. }
  28. },
  29. messages: {
  30. name: {
  31. required: "Please enter your name.",
  32. lettersonly: "Needs to be letters, no numbers please."
  33. },
  34. email: {
  35. required: "Please enter your email adress.",
  36. email: "Please enter your valid email adress."
  37. },
  38. phone: {
  39.  
  40. },
  41. message:{
  42. required: "Please enter a message.",
  43. }
  44. },
  45.  
  46. submitHandler: function(form) {
  47. $('#contact-msg').html('<p class="ajaxLoader">Sending Email...</p>');
  48.  
  49. $.ajax ({
  50. type: 'POST',
  51. url: ajax_object.ajax_url,
  52. data: $('#contact-form').serialize(),
  53. dataType: 'json',
  54. success: function(response) {
  55. if (response.status == 'success') {
  56. $('#contact-form')[0].reset();
  57. }
  58. $('#contact-msg').html(response.errmessage);
  59. }
  60. });
  61.  
  62. }
  63.  
  64. });
  65. });
  66.  
  67. // CONTACT FORM SCRIPTS
  68. function contactform_add_script() {
  69.  
  70. wp_enqueue_script( 'contactform-script', get_template_directory_uri().'/assets/js/contact_me.js', array('jquery') , null, true);
  71. wp_localize_script( 'contactform-script', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
  72.  
  73. }
  74. add_action('wp_enqueue_scripts', 'contactform_add_script');
  75.  
  76.  
  77. // CONTACT FORM PROCESSING
  78. function ajax_contactform_action_callback() {
  79. $error = '';
  80. $status = 'error';
  81. if (empty($_POST['name']) || empty($_POST['email']) || empty($_POST['message'])) {
  82. $error = 'All fields are required to enter.';
  83.  
  84. } else {
  85. $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
  86. $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
  87. $number = filter_var($_POST['phone'], FILTER_SANITIZE_NUMBER_INT);
  88. // $treatments = filter_var($_POST['treatments'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
  89. $subject = 'A message from St. Romain Interiors's contact form.';
  90. $message .= PHP_EOL.'Sender's name: '.$name;
  91. $message .= PHP_EOL.'Phone number: '.$number;
  92. $message .= PHP_EOL.'E-mail address: '.$email;
  93.  
  94. $message .= PHP_EOL.'Message: '.stripslashes($_POST['message']);
  95.  
  96. $sendmsg = "Thanks for the message! We will respond as soon as possible.";
  97. $to = 'blah@gmail.com'; // If you like change this email address
  98. // replace "noreply@yourdomain.com" with your real email address
  99.  
  100. $header .= 'Reply-To: '.$email.PHP_EOL;
  101. if ( wp_mail($to, $subject, $message, $header) ) {
  102. $status = 'success';
  103. $error = $sendmsg;
  104. } else {
  105. $error = 'Some errors occurred.';
  106. }
  107. }
  108.  
  109. $resp = array('status' => $status, 'errmessage' => $error);
  110. header( "Content-Type: application/json" );
  111. echo json_encode($resp);
  112. die();
  113. }
  114. add_action( 'wp_ajax_contactform_action', 'ajax_contactform_action_callback' );
  115. add_action( 'wp_ajax_nopriv_contactform_action', 'ajax_contactform_action_callback' );
  116.  
  117. submitHandler: function(form) {
  118. $('#contact-msg').html('<p class="ajaxLoader">Sending Email...</p>');
  119.  
  120. $.ajax ({
  121. type: 'POST',
  122. url: ajax_object.ajax_url,
  123. data: { action: "contactform_action",
  124. values: $('#contact-form').serialize() },
  125. dataType: 'json',
  126. success: function(response) {
  127.  
  128. $('#contact-msg').html('<p>Thanks for the message!</p>');
  129. }
  130. });
  131.  
  132. }
  133.  
  134. X-Robots-Tag: noindex
  135. X-Powered-By: PHP/5.6.14
  136. x-frame-options: SAMEORIGIN
  137. x-content-type-options: nosniff
  138. Transfer-Encoding: chunked
  139. Server: Apache
  140. Pragma: no-cache
  141. Expires: Wed, 11 Jan 1984 05:00:00 GMT
  142. Date: Mon, 26 Oct 2015 06:13:54 GMT
  143. Content-Type: application/json
  144. Cache-Control: no-cache, must-revalidate, max-age=0
  145.  
  146. <br />
  147. <b>Notice</b>: Undefined index: name in <b>/home/theski/public_html/stromain/wp-content/themes/stromain
  148. /functions.php</b> on line <b>156</b><br />
  149. <br />
  150. <b>Notice</b>: Undefined index: email in <b>/home/theski/public_html/stromain/wp-content/themes/stromain
  151. /functions.php</b> on line <b>157</b><br />
  152. <br />
  153. <b>Notice</b>: Undefined index: phone in <b>/home/theski/public_html/stromain/wp-content/themes/stromain
  154. /functions.php</b> on line <b>158</b><br />
  155. <br />
  156. <b>Notice</b>: Undefined variable: message in<b>/home/theski/public_html/stromain/wp-content/themes
  157. /stromain/functions.php</b> on line <b>161</b><br />
  158. <br />
  159. <b>Notice</b>: Undefined index: message in <b>/home/theski/public_html/stromain/wp-content/themes/stromain
  160. /functions.php</b> on line <b>165</b><br />
  161. <br />
  162. <b>Notice</b>: Undefined variable: header in <b>/home/theski/public_html/stromain/wp-content/themes
  163. /stromain/functions.php</b> on line <b>171</b><br />
  164. {"status":"success","errmessage":"Thanks for the message! We will respond as soon as possible."}
  165.  
  166. data: {action: "contactform_action", values: $('#contact-form').serialize()}
Add Comment
Please, Sign In to add comment