Advertisement
firoze

template-contact.php

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