Guest User

Untitled

a guest
Jan 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.00 KB | None | 0 0
  1. <?php
  2. /**
  3. * Template Name: Contact Form
  4. *
  5. * The contact form page template displays the a
  6. * simple contact form in your website's content area.
  7. *
  8. * @package WooFramework
  9. * @subpackage Template
  10. */
  11.  
  12. get_header();
  13.  
  14. $nameError = '';
  15. $emailError = '';
  16. $commentError = '';
  17.  
  18. //If the form is submitted
  19. if( isset( $_POST['submitted'] ) ) {
  20.  
  21. //Check to see if the honeypot captcha field was filled in
  22. if( trim( $_POST['checking'] ) !== '' ) {
  23. $captchaError = true;
  24. } else {
  25.  
  26. //Check to make sure that the name field is not empty
  27. if( trim( $_POST['contactName'] ) === '' ) {
  28. $nameError = __( 'You forgot to enter your name.', 'woothemes' );
  29. $hasError = true;
  30. } else {
  31. $name = trim( $_POST['contactName'] );
  32. }
  33.  
  34. //Check to make sure sure that a valid email address is submitted
  35. if(trim($_POST['email']) === '') {
  36. $emailError = __( 'You forgot to enter your email address.', 'woothemes' );
  37. $hasError = true;
  38. } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
  39. $emailError = __( 'You entered an invalid email address.', 'woothemes' );
  40. $hasError = true;
  41. } else {
  42. $email = trim($_POST['email']);
  43. }
  44.  
  45. //Check to make sure comments were entered
  46. if( trim( $_POST['comments'] ) === '' ) {
  47. $commentError = __( 'You forgot to enter your comments.', 'woothemes' );
  48. $hasError = true;
  49. } else {
  50. if(function_exists('stripslashes')) {
  51. $comments = stripslashes(trim($_POST['comments']));
  52. } else {
  53. $comments = trim($_POST['comments']);
  54. }
  55. }
  56.  
  57. //If there is no error, send the email
  58. if(!isset($hasError)) {
  59.  
  60. $emailTo = get_option('woo_contactform_email');
  61. $subject = __( 'Contact Form Submission from ', 'woothemes' ).$name;
  62. $sendCopy = trim($_POST['sendCopy']);
  63. $body = __( 'Name:', 'woothemes' ) . ' ' . $name . "\n\n" . __( 'Email:', 'woothemes' ) . ' ' . $email . "\n\n" . __( 'Comments:', 'woothemes' ) . ' ' . $comments;
  64. $headers = __( 'From: ', 'woothemes' ) . stripslashes(get_bloginfo( 'title' )).' <'.$email.'>';
  65.  
  66. wp_mail($emailTo, $subject, $body, $headers);
  67.  
  68. if($sendCopy == true) {
  69. $subject = __( 'You emailed ', 'woothemes' ).stripslashes(get_bloginfo('title'));
  70. $headers = __( 'From: ','woothemes' ) . '<'.$emailTo.'>';
  71. wp_mail($email, $subject, $body, $headers);
  72. }
  73.  
  74. $emailSent = true;
  75.  
  76. }
  77. }
  78. } ?>
  79.  
  80.  
  81. <?php get_header(); ?>
  82.  
  83. <script type="text/javascript">
  84. <!--//--><![CDATA[//><!--
  85. jQuery(document).ready(function() {
  86. jQuery('form#contactForm').submit(function() {
  87. jQuery('form#contactForm .error').remove();
  88. var hasError = false;
  89. jQuery('.requiredField').each(function() {
  90. if(jQuery.trim(jQuery(this).val()) == '') {
  91. var labelText = jQuery(this).prev('label').text();
  92. jQuery(this).parent().append('<span class="error"><?php _e( 'You forgot to enter your', 'woothemes' ); ?> '+labelText+'.</span>');
  93. jQuery(this).addClass('inputError');
  94. hasError = true;
  95. } else if(jQuery(this).hasClass('email')) {
  96. var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  97. if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
  98. var labelText = jQuery(this).prev('label').text();
  99. jQuery(this).parent().append('<span class="error"><?php _e( 'You entered an invalid', 'woothemes' ); ?> '+labelText+'.</span>');
  100. jQuery(this).addClass('inputError');
  101. hasError = true;
  102. }
  103. }
  104. });
  105. if(!hasError) {
  106. var formInput = jQuery(this).serialize();
  107. jQuery.post(jQuery(this).attr('action'),formInput, function(data){
  108. jQuery('form#contactForm').slideUp("fast", function() {
  109. jQuery(this).before('<p class="tick"><?php _e( '<strong>Thanks!</strong> Your email was successfully sent.', 'woothemes' ); ?></p>');
  110. });
  111. });
  112. }
  113.  
  114. return false;
  115.  
  116. });
  117. });
  118. //-->!]]>
  119. </script>
  120.  
  121. <!-- #content Starts -->
  122. <?php woo_content_before(); ?>
  123. <div id="content" class="col-full">
  124.  
  125.  
  126. <div id="main-sidebar-container">
  127.  
  128. <!-- #main Starts -->
  129. <?php woo_main_before(); ?>
  130. <div id="main">
  131.  
  132. <?php woo_loop_before(); ?>
  133. <!-- Post Starts -->
  134. <?php woo_post_before(); ?>
  135. <div id="contact-page" <?php post_class(); ?>>
  136.  
  137. <?php woo_post_inside_before(); ?>
  138.  
  139. <h1 class="title"><?php the_title(); ?></h1>
  140.  
  141. <?php if( isset( $emailSent ) && $emailSent == true ) { ?>
  142.  
  143. <p class="info"><?php _e( 'Your email was successfully sent.', 'woothemes' ); ?></p>
  144.  
  145. <?php } else { ?>
  146.  
  147. <?php if ( have_posts() ) { ?>
  148. <?php while ( have_posts() ) { the_post(); ?>
  149.  
  150. <div class="entry">
  151. <?php the_content(); ?>
  152. </div>
  153.  
  154. <?php if(isset($hasError) || isset($captchaError) ) { ?>
  155. <p class="alert"><?php _e( 'There was an error submitting the form.', 'woothemes' ); ?></p>
  156. <?php } ?>
  157.  
  158. <?php if ( get_option('woo_contactform_email') == '' ) { ?>
  159. <p class="alert"><?php _e( 'E-mail has not been setup properly. Please add your contact e-mail!', 'woothemes' ); ?></p>
  160. <?php } ?>
  161.  
  162.  
  163. <form action="<?php the_permalink(); ?>" id="contactForm" method="post">
  164.  
  165. <ol class="forms">
  166. <li><label for="contactName"><?php _e('Name', 'woothemes'); ?></label>
  167. <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="txt requiredField" />
  168. <?php if($nameError != '') { ?>
  169. <span class="error"><?php echo $nameError; ?></span>
  170. <?php } ?>
  171. </li>
  172.  
  173. <li><label for="email"><?php _e('Email', 'woothemes'); ?></label>
  174. <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="txt requiredField email" />
  175. <?php if($emailError != '') { ?>
  176. <span class="error"><?php echo $emailError; ?></span>
  177. <?php } ?>
  178. </li>
  179.  
  180. <li class="textarea"><label for="commentsText"><?php _e('Message', 'woothemes'); ?></label>
  181. <textarea name="comments" id="commentsText" rows="20" cols="30" class="requiredField"><?php if(isset($_POST['comments'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comments']); } else { echo $_POST['comments']; } } ?></textarea>
  182. <?php if($commentError != '') { ?>
  183. <span class="error"><?php echo $commentError; ?></span>
  184. <?php } ?>
  185. </li>
  186. <li class="inline"><input type="checkbox" name="sendCopy" id="sendCopy" value="true"<?php if(isset($_POST['sendCopy']) && $_POST['sendCopy'] == true) echo ' checked="checked"'; ?> /><label for="sendCopy"><?php _e('Send a copy of this email to yourself', 'woothemes'); ?></label></li>
  187. <li class="screenReader"><label for="checking" class="screenReader"><?php _e('If you want to submit this form, do not enter anything in this field', 'woothemes') ?></label><input type="text" name="checking" id="checking" class="screenReader" value="<?php if(isset($_POST['checking'])) echo $_POST['checking'];?>" /></li>
  188. <li class="buttons"><input type="hidden" name="submitted" id="submitted" value="true" /><input class="submit button" type="submit" value="<?php _e('Submit', 'woothemes'); ?>" /></li>
  189. </ol>
  190. </form>
  191.  
  192. <?php
  193. } // End WHILE Loop
  194. } // End IF Statement
  195. ?>
  196. <?php } ?>
  197. <div class="fix"></div>
  198.  
  199. <?php woo_post_inside_after(); ?>
  200.  
  201. </div><!-- /.post -->
  202. <?php woo_post_after(); ?>
  203.  
  204. </div><!-- /#main -->
  205. <?php woo_main_after(); ?>
  206.  
  207. <?php get_sidebar(); ?>
  208.  
  209. </div><!-- /#main-sidebar-container -->
  210.  
  211. <?php get_sidebar( 'alt' ); ?>
  212.  
  213. </div><!-- /#content -->
  214. <?php woo_content_after(); ?>
  215.  
  216. <?php get_footer(); ?>
Add Comment
Please, Sign In to add comment