Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. <?php
  2. /*
  3. Template Name: Contact Form
  4. */
  5. ?>
  6.  
  7. <?php
  8. //If the form is submitted
  9. if(isset($_POST['submitted'])) {
  10.  
  11. //Check to see if the honeypot captcha field was filled in
  12. if(trim($_POST['checking']) !== '') {
  13. $captchaError = true;
  14. } else {
  15.  
  16. //Check to make sure that the name field is not empty
  17. if(trim($_POST['contactName']) === '') {
  18. $nameError = __('You forgot to enter your name.', 'woothemes');
  19. $hasError = true;
  20. } else {
  21. $name = trim($_POST['contactName']);
  22. }
  23.  
  24. //Check to make sure sure that a valid email address is submitted
  25. if(trim($_POST['email']) === '') {
  26. $emailError = __('You forgot to enter your email address.', 'woothemes');
  27. $hasError = true;
  28. } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
  29. $emailError = __('You entered an invalid email address.', 'woothemes');
  30. $hasError = true;
  31. } else {
  32. $email = trim($_POST['email']);
  33. }
  34.  
  35. //Check to make sure comments were entered
  36. if(trim($_POST['comments']) === '') {
  37. $commentError = __('You forgot to enter your comments.', 'woothemes');
  38. $hasError = true;
  39. } else {
  40. if(function_exists('stripslashes')) {
  41. $comments = stripslashes(trim($_POST['comments']));
  42. } else {
  43. $comments = trim($_POST['comments']);
  44. }
  45. }
  46.  
  47. //If there is no error, send the email
  48. if(!isset($hasError)) {
  49.  
  50. $emailTo = get_option('woo_contactform_email');
  51. $subject = __('Contact Form Submission from ', 'woothemes').$name;
  52. $sendCopy = trim($_POST['sendCopy']);
  53. $body = __("Name: $name \n\nEmail: $email \n\nComments: $comments", 'woothemes');
  54. $headers = __('From: ', 'woothemes') .' <'.$email.'>' . "\r\n" . __('Reply-To: ','woothemes') . $email;
  55.  
  56. //Modified 2010-04-29 (fox)
  57. wp_mail($emailTo, $subject, $body, $headers);
  58.  
  59. if($sendCopy == true) {
  60. $subject = __('You emailed ', 'woothemes').get_bloginfo('title');
  61. $headers = __('From: ','woothemes') . '<'.$emailTo.'>';
  62. wp_mail($email, $subject, $body, $headers);
  63. }
  64.  
  65. $emailSent = true;
  66.  
  67. }
  68. }
  69. } ?>
  70.  
  71.  
  72. <?php get_header(); ?>
  73.  
  74. <script type="text/javascript">
  75. <!--//--><![CDATA[//><!--
  76. jQuery(document).ready(function() {
  77. jQuery('form#contactForm').submit(function() {
  78. jQuery('form#contactForm .error').remove();
  79. var hasError = false;
  80. jQuery('.requiredField').each(function() {
  81. if(jQuery.trim(jQuery(this).val()) == '') {
  82. var labelText = jQuery(this).prev('label').text();
  83. jQuery(this).parent().append('<span class="error"><?php _e('You forgot to enter your', 'woothemes'); ?> '+labelText+'.</span>');
  84. jQuery(this).addClass('inputError');
  85. hasError = true;
  86. } else if(jQuery(this).hasClass('email')) {
  87. var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  88. if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
  89. var labelText = jQuery(this).prev('label').text();
  90. jQuery(this).parent().append('<span class="error"><?php _e('You entered an invalid', 'woothemes'); ?> '+labelText+'.</span>');
  91. jQuery(this).addClass('inputError');
  92. hasError = true;
  93. }
  94. }
  95. });
  96. if(!hasError) {
  97. var formInput = jQuery(this).serialize();
  98. jQuery.post(jQuery(this).attr('action'),formInput, function(data){
  99. jQuery('form#contactForm').slideUp("fast", function() {
  100. jQuery(this).before('<p class="tick"><?php _e('<strong>Thanks!</strong> Your email was successfully sent.', 'woothemes'); ?></p>');
  101. });
  102. });
  103. }
  104.  
  105. return false;
  106.  
  107. });
  108. });
  109. //-->!]]>
  110. </script>
  111.  
  112. <div id="content" class="col-full">
  113. <div id="main" class="col-left">
  114. <?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<div id="breadcrumb"><p>','</p></div>'); } ?>
  115. <div id="contact-page" class="post page">
  116.  
  117. <?php if(isset($emailSent) && $emailSent == true) { ?>
  118.  
  119. <p class="info"><?php _e('Your email was successfully sent.', 'woothemes'); ?></p>
  120.  
  121. <?php } else { ?>
  122.  
  123. <?php if (have_posts()) : ?>
  124.  
  125. <?php while (have_posts()) : the_post(); ?>
  126.  
  127. <h1 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1>
  128.  
  129. <div class="entry">
  130. <?php the_content(); ?>
  131. </div>
  132.  
  133. <?php if(isset($hasError) || isset($captchaError) ) { ?>
  134. <p class="alert"><?php _e('There was an error submitting the form.', 'woothemes'); ?></p>
  135. <?php } ?>
  136.  
  137. <?php if ( get_option('woo_contactform_email') == '' ) { ?>
  138. <?php echo do_shortcode('[box type="alert"]'.__('E-mail has not been setup properly. Please add your contact e-mail!', 'woothemes').'[/box]'); ?>
  139. <?php } ?>
  140.  
  141.  
  142. <form action="<?php the_permalink(); ?>" id="contactForm" method="post">
  143.  
  144. <ol class="forms">
  145. <li><label for="contactName"><?php _e('Name', 'woothemes'); ?></label>
  146. <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="txt requiredField" />
  147. <?php if($nameError != '') { ?>
  148. <span class="error"><?php echo $nameError;?></span>
  149. <?php } ?>
  150. </li>
  151.  
  152. <li><label for="email"><?php _e('Email', 'woothemes'); ?></label>
  153. <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="txt requiredField email" />
  154. <?php if($emailError != '') { ?>
  155. <span class="error"><?php echo $emailError;?></span>
  156. <?php } ?>
  157. </li>
  158.  
  159. <li class="textarea"><label for="commentsText"><?php _e('Message', 'woothemes'); ?></label>
  160. <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>
  161. <?php if($commentError != '') { ?>
  162. <span class="error"><?php echo $commentError;?></span>
  163. <?php } ?>
  164. </li><noscript>
  165. <style type='text/css'>#submit {display:none;}</style>
  166. <input name="submit" type="submit" id="submit-alt" tabindex="6" value="Submit Comment"/>
  167. </noscript>
  168.  
  169. <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>
  170. <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>
  171. <li class="buttons"><input type="hidden" name="submitted" id="submitted" value="true" /><input class="submit button" type="submit" value="<?php _e('Submit', 'woothemes'); ?>" /></li>
  172. </ol>
  173. </form>
  174.  
  175. <?php endwhile; ?>
  176. <?php endif; ?>
  177. <?php } ?><script type="text/javascript">
  178. var sub = document.getElementById('submit');
  179. document.getElementById('recaptcha-submit-btn-area').appendChild (sub);
  180. document.getElementById('submit').tabIndex = 6;
  181. if ( typeof _recaptcha_wordpress_savedcomment != 'undefined') {
  182. document.getElementById('comment').value = _recaptcha_wordpress_savedcomment;
  183. }
  184. document.getElementById('recaptcha_table').style.direction = 'ltr';
  185. </script>
  186. <div class="fix"></div>
  187. </div><!-- /#contact-page -->
  188. </div><!-- /#main -->
  189.  
  190. <?php get_sidebar(); ?>
  191.  
  192. </div><!-- /#content -->
  193.  
  194. <?php get_footer(); ?>
  195.