Advertisement
ovizii

contact-page.php

Oct 10th, 2014
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*
  4. Template Name: Contact Us
  5. */
  6.  
  7. ?>
  8.  
  9. <?php
  10.     // Fetch options stored in $data
  11.     global $data;
  12. ?>
  13.  
  14. <?php
  15.  
  16.     // Email Contact Form
  17.     $name_error = '';
  18.     $email_error = '';
  19.     $contact_error = '';
  20.    
  21.     if(isset($_POST['sent'])) {
  22.        
  23.         if(trim($_POST['contact_name']) === '') {
  24.             $name_error = __('Name is a required field', 'qns');
  25.             $got_error = true;
  26.         }
  27.    
  28.         else {
  29.             $name = trim($_POST['contact_name']);
  30.         }
  31.        
  32.         if(trim($_POST['email']) === '')  {
  33.             $email_error = __('Email is a required field', 'qns');
  34.             $got_error = true;
  35.         }
  36.    
  37.         else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
  38.             $email_error = __('Invalid email address', 'qns');
  39.             $got_error = true;
  40.         }
  41.    
  42.         else {
  43.             $email = trim($_POST['email']);
  44.         }
  45.            
  46.         if(trim($_POST['message']) === '') {
  47.             $contact_error = __('Message is a required field', 'qns');
  48.             $got_error = true;
  49.         }
  50.    
  51.         else {
  52.        
  53.             if(function_exists('stripslashes')) {
  54.                 $message = stripslashes(trim($_POST['message']));
  55.             }
  56.        
  57.             else {
  58.                 $message = trim($_POST['message']);
  59.             }
  60.        
  61.         }
  62.            
  63.         if(!isset($got_error)) {
  64.        
  65.             $email_to = $data['contact_email'];
  66.        
  67.             if (!isset($email_to) || ($email_to == '') ){
  68.                 $email_to = get_option('admin_email');
  69.             }
  70.        
  71.         $subject = get_bloginfo( 'name' ) . __(' Contact Form','qns');
  72.         $body = $message . "<br /><br /> " . __('IP Address','qns') . ": " . $_SERVER['REMOTE_ADDR'];
  73.            
  74.         $headers = "MIME-Version: 1.0\r\n";
  75.         $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  76.         $headers .= 'From: '.$name.' <'.$email_to.'>' . "\r\n" . 'Reply-To: ' . $email;
  77.            
  78.         mail($email_to, $subject, $body, $headers);
  79.         $emailSent = true;
  80.        
  81.     }
  82.    
  83. } ?>
  84.  
  85. <?php get_header(); ?>
  86.    
  87.     <?php //Display Page Header
  88.         global $wp_query;
  89.         $postid = $wp_query->post->ID;
  90.         echo page_header( get_post_meta($postid, 'qns_page_header_image', true) );
  91.         wp_reset_query();
  92.     ?>
  93.    
  94.     <!-- BEGIN .section -->
  95.     <div class="section">
  96.        
  97.         <ul class="columns-content page-content clearfix">
  98.            
  99.             <!-- BEGIN .col-main -->
  100.             <li class="<?php echo sidebar_position('primary-content'); ?>">
  101.            
  102.                 <h2 class="page-title"><?php the_title(); ?></h2>
  103.  
  104.                 <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  105.  
  106.                     <?php      
  107.                         $street_address = '';
  108.                         $phone_number = '';
  109.                         $email_address = '';
  110.                    
  111.                         if ( $data['street_address'] ) {
  112.                             $street_address = $data['street_address'];
  113.                         }
  114.                    
  115.                         if ( $data['phone_number'] ) {
  116.                             $phone_number = $data['phone_number'];
  117.                         }
  118.                    
  119.                         if ( $data['email_address'] ) {
  120.                             $email_address = $data['email_address'];
  121.                         }  
  122.                     ?>
  123.                
  124.                     <?php // No Content
  125.                         if ( $post->post_content == "" ) { $no_the_content = true; } else { $no_the_content = false; }
  126.                     ?>
  127.                
  128.                     <?php // No Contact Details
  129.                         if ( !$street_address && !$phone_number && !$email_address ) { $no_details = true; } else { $no_details = false; }
  130.                     ?>
  131.                
  132.                     <?php // Some Contact Details
  133.                         if ( $street_address !== '' or $phone_number !== '' or $email_address !== '' ) { $some_details = true; } else { $some_details = false; }
  134.                     ?>
  135.                
  136.                     <?php // No Content, Some Contact Details
  137.                         if ( $some_details == true && $no_the_content == true ) { ?>
  138.                        
  139.                             <h4><?php _e ( 'Details','qns' )?></h4>
  140.                        
  141.                             <!--BEGIN .contact_list -->
  142.                             <ul class="contact_list">
  143.                                 <?php if ( $street_address ) { ?><li class="address"><span><?php _e($data['street_address'],'qns'); ?></span></li><?php } ?>
  144.                                 <?php if ( $phone_number ) { ?><li class="phone"><span><?php _e($data['phone_number'],'qns'); ?></span></li><?php } ?>
  145.                                 <?php if ( $email_address ) { ?><li class="email"><span><?php _e($data['email_address'],'qns'); ?></span></li><?php } ?>
  146.                             <!--END .contact_list -->
  147.                             </ul>
  148.                    
  149.                         <?php } ?>
  150.                
  151.                         <?php // Content, No Contact Details
  152.                         if ( $no_details == true && $no_the_content == false ) {
  153.                             the_content();
  154.                         } ?>
  155.                
  156.                         <?php // Content and Contact Details
  157.                             if ( $some_details == true && $no_the_content == false ) { ?>
  158.                    
  159.                                 <ul class="columns-2 clearfix">
  160.                                     <li class="col2">
  161.                                         <?php the_content(); ?>
  162.                                     </li>
  163.                            
  164.                                     <li class="col2">
  165.                                         <h4><?php _e( 'Details','qns' )?></h4>
  166.                            
  167.                                         <!--BEGIN .contact_list -->
  168.                                         <ul class="contact_list">
  169.                                             <?php if ( $street_address ) { ?><li class="address"><span><?php _e($data['street_address'],'qns'); ?></span></li><?php } ?>
  170.                                             <?php if ( $phone_number ) { ?><li class="phone"><span><?php _e($data['phone_number'],'qns'); ?></span></li><?php } ?>
  171.                                             <?php if ( $email_address ) { ?><li class="email"><span><?php _e($data['email_address'],'qns'); ?></span></li><?php } ?>
  172.                                         <!--END .contact_list -->
  173.                                         </ul>
  174.                                     </li>
  175.                                 </ul>
  176.                    
  177.                             <?php } ?>
  178.                
  179.                         <?php endwhile; endif; ?>
  180.        
  181.                         <?php
  182.                        
  183.                             if ( $data['gmap-content'] ) {
  184.                                 $marker_html = ' marker_html="' . $data['gmap-content'] . '"';
  185.                             }
  186.                            
  187.                             if ( $data['map_latitude'] ) {
  188.                                 $map_latitude = $data['map_latitude'];
  189.                             }
  190.                             else {
  191.                                 $map_latitude = '51.508515';
  192.                             }
  193.                            
  194.                             if ( $data['map_longitude'] ) {
  195.                                 $map_longitude = $data['map_longitude'];
  196.                             }
  197.                             else {
  198.                                 $map_longitude = '-0.125487';
  199.                             }
  200.                        
  201.                             // If the Google Maps option is selected display the map
  202.                             if ( $data['map_latitude'] && $data['map_longitude'] ) {
  203.                                 echo do_shortcode('[googlemap height="250px"' . $marker_html . ' latitude="' . $map_latitude . '" longitude="' . $map_longitude . '"]');
  204.                             }
  205.  
  206.                             // If the contact form has errors display them to the user
  207.                             if ( $got_error == true ) {
  208.  
  209.                                 echo '<div class="msg fail">
  210.                                 <ul class="list-fail">';
  211.  
  212.                                 if ( $name_error != '' ) { echo '<li>' . $name_error . '</li>'; }
  213.                                 if ( $email_error != '' ) { echo '<li>' . $email_error . '</li>'; }
  214.                                 if ( $contact_error != '' ) { echo '<li>' . $contact_error . '</li>'; }
  215.  
  216.                                 echo '</ul></div>';
  217.  
  218.                             }
  219.                        
  220.                             // If there are no problems with the email and it has been sent display this message
  221.                             if (isset($emailSent) && $emailSent == true) : ?>
  222.            
  223.                                 <div class="msg success clearfix">
  224.                                     <p class="fl"><?php _e('Email sent, thank you for contacting us', 'qns') ?></p>
  225.                                 </div>
  226.  
  227.                             <?php else : ?>
  228.            
  229.                             <h4><?php _e('Send Us An Email', 'qns') ?></h4>
  230.            
  231.                             <form action="<?php the_permalink(); ?>" id="contactform" class="clearfix" method="post">
  232.  
  233.                                 <div class="field-row">
  234.                                     <label for="contact_name"><?php _e('Name', 'qns') ?>
  235.                                         <span>(<?php _e('required', 'qns') ?>)</span>
  236.                                     </label>
  237.                                     <input type="text" name="contact_name" id="contact_name" class="text_input" value="<?php if(isset($_POST['contact_name'])) echo $_POST['contact_name'];?>" />
  238.                                 </div>
  239.  
  240.                                 <div class="field-row">
  241.                                     <label for="email"><?php _e('Email', 'qns') ?>
  242.                                         <span>(<?php _e('required', 'qns') ?>)</span>
  243.                                     </label>
  244.                                     <input type="text" name="email" id="email" class="text_input" value="<?php if(isset($_POST['email']))  echo $_POST['email'];?>" />     
  245.                                 </div>
  246.  
  247.                                 <div class="field-row">
  248.                                     <label for="message_text"><?php _e('Message', 'qns') ?>
  249.                                         <span>(<?php _e('required', 'qns') ?>)</span>
  250.                                     </label>
  251.                                    
  252.                                     <textarea name="message" id="message_text" class="text_input" cols="60" rows="9"><?php if(isset($_POST['message'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['message']); } else { echo $_POST['message']; } } ?></textarea>
  253.                                 </div>
  254.                
  255.                                 <input class="button2" type="submit" value="<?php _e('Send Email', 'qns') ?>" name="submit">
  256.                                 <input type="hidden" name="sent" value="true" />
  257.                
  258.                             </form>
  259.                            
  260.                             <?php endif; ?>
  261.                    
  262.                 <!-- END .col-main -->
  263.                 </li>
  264.            
  265.             <?php get_sidebar(); ?>
  266.        
  267.         </ul>
  268.        
  269.         <!-- END .section -->      
  270.         </div>
  271.  
  272. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement