Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

Contact Form Page Template
Thursday, March 14th, 2013 at 3:08:38am UTC 

  1. <?php
  2.  
  3.   //response generation function
  4.  
  5.   $response = "";
  6.  
  7.   //function to generate response
  8.   function generate_response($type, $message){
  9.    
  10.     global $response;
  11.  
  12.     if($type == "success") $response = "<div class='success'>{$message}</div>";
  13.     else $response = "<div class='error'>{$message}</div>";
  14.    
  15.   }
  16.  
  17.   //response messages
  18.   $not_human       = "Human verification incorrect.";
  19.   $missing_content = "Please supply all information.";
  20.   $email_invalid   = "Email Address Invalid.";
  21.   $message_unsent  = "Message was not sent. Try Again.";
  22.   $message_sent    = "Thanks! Your message has been sent.";
  23.  
  24.   //user posted variables
  25.   $name = $_POST['message_name'];
  26.   $email = $_POST['message_email'];
  27.   $message = $_POST['message_text'];
  28.   $human = $_POST['message_human'];
  29.  
  30.   //php mailer variables
  31.   $to = get_option('admin_email');
  32.   $subject = "Someone sent a message from ".get_bloginfo('name');
  33.   $headers = 'From: '. $email . "\r\n" .
  34.     'Reply-To: ' . $email . "\r\n";
  35.  
  36.   if(!$human == 0){
  37.     if($human != 2) generate_response("error", $not_human); //not human!
  38.     else {
  39.      
  40.       //validate email
  41.       if(!filter_var($email, FILTER_VALIDATE_EMAIL))
  42.         generate_response("error", $email_invalid);
  43.       else //email is valid
  44.       {
  45.         //validate presence of name and message
  46.         if(empty($name) || empty($message)){
  47.           generate_response("error", $missing_content);
  48.         }
  49.         else //ready to go!
  50.         {
  51.           $sent = mail($to, $subject, $message, $headers);
  52.           if($sent) generate_response("success", $message_sent); //message sent!
  53.           else generate_response("error", $message_unsent); //message wasn't sent
  54.         }
  55.       }
  56.     }
  57.   }
  58.   else if ($_POST['submitted']) generate_response("error", $missing_content);
  59.  
  60. ?>
  61.  
  62. <?php get_header(); ?>
  63.  
  64.   <div id="primary" class="site-content">
  65.     <div id="content" role="main">
  66.  
  67.       <?php while ( have_posts() ) : the_post(); ?>
  68.  
  69.           <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
  70.  
  71.             <header class="entry-header">
  72.               <h1 class="entry-title"><?php the_title(); ?></h1>
  73.             </header>
  74.  
  75.             <div class="entry-content">
  76.               <?php the_content(); ?>
  77.  
  78.               <style type="text/css">
  79.                 .error{
  80.                   padding: 5px 9px;
  81.                   border: 1px solid red;
  82.                   color: red;
  83.                   border-radius: 3px;
  84.                 }
  85.  
  86.                 .success{
  87.                   padding: 5px 9px;
  88.                   border: 1px solid green;
  89.                   color: green;
  90.                   border-radius: 3px;
  91.                 }
  92.  
  93.                 form span{
  94.                   color: red;
  95.                 }
  96.               </style>
  97.  
  98.               <div id="respond">
  99.                 <?php echo $response; ?>
  100.                 <form action="<?php the_permalink(); ?>" method="post">
  101.                   <p><label for="name">Name: <span>*</span> <br><input type="text" name="message_name" value="<?php echo $_POST['message_name']; ?>"></label></p>
  102.                   <p><label for="message_email">Email: <span>*</span> <br><input type="text" name="message_email" value="<?php echo $_POST['message_email']; ?>"></label></p>
  103.                   <p><label for="message_text">Message: <span>*</span> <br><textarea type="text" name="message_text"><?php echo $_POST['message_text']; ?></textarea></label></p>
  104.                   <p><label for="message_human">Human Verification: <span>*</span> <br><input type="text" style="width: 60px;" name="message_human"> + 3 = 5</label></p>
  105.                   <input type="hidden" name="submitted" value="1">
  106.                   <p><input type="submit"></p>
  107.                 </form>
  108.               </div>
  109.  
  110.  
  111.             </div><!-- .entry-content -->
  112.  
  113.           </article><!-- #post -->
  114.  
  115.       <?php endwhile; // end of the loop. ?>
  116.  
  117.     </div><!-- #content -->
  118.   </div><!-- #primary -->
  119.  
  120. <?php get_sidebar(); ?>
  121. <?php get_footer(); ?>

advertising

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus