Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Template Name: Contact Form
- *
- * Contact form without a plugin
- * http://trevordavis.net/blog/wordpress-jquery-contact-form-without-a-plugin/
- *
- */
- //If the form is submitted
- if(isset($_POST['submitted'])) {
- //Check to see if the honeypot captcha field was filled in
- if(trim($_POST['checking']) !== '') {
- $captchaError = true;
- } else {
- //Check to make sure that the name field is not empty
- if(trim($_POST['contactName']) === '') {
- $nameError = __('Error: please fill the required fields (name, email).');
- $hasError = true;
- } else {
- $name = trim($_POST['contactName']);
- }
- //Check to make sure sure that a valid email address is submitted
- if(trim($_POST['email']) === '') {
- $emailError = __('Error: please fill the required fields (name, email).');
- $hasError = true;
- } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
- $emailError = __('You entered an invalid email address.', 'ip4all');
- $hasError = true;
- } else {
- $email = trim($_POST['email']);
- }
- //Check to make sure comments were entered
- if(trim($_POST['comments']) === '') {
- $commentError = __('Error: please type a comment.');
- $hasError = true;
- } else {
- if(function_exists('stripslashes')) {
- $comments = stripslashes(trim($_POST['comments']));
- } else {
- $comments = trim($_POST['comments']);
- }
- }
- //If there is no error, send the email
- if(!isset($hasError)) {
- $emailTo = get_option('admin_email');
- if(trim($_POST['subject']) === '') {
- $subject = '[' . get_bloginfo('name') . '] ' . __('Contact Form Submission from', 'ip4all') . ' ' . $name;
- } else {
- $subject = '[' . get_bloginfo('name') . '] ' . $name . ': ' . trim($_POST['comments']);
- }
- $sendCopy = trim($_POST['sendCopy']);
- $body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
- $headers = 'From: ' . get_bloginfo('name') . ' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
- mail($emailTo, $subject, $body, $headers);
- if($sendCopy == true) {
- $subject = 'You emailed ' . get_bloginfo('name') ;
- mail($email, $subject, $body, $headers);
- }
- $emailSent = true;
- }
- }
- } ?>
- <?php
- // calling the header.php
- get_header();
- // action hook for placing content above #container
- thematic_abovecontainer();
- ?>
- <div id="container">
- <?php thematic_abovecontent(); ?>
- <div id="content">
- <?php
- // calling the widget area 'page-top'
- // get_sidebar('page-top');
- the_post();
- thematic_abovepost();
- ?>
- <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class() ?>">
- <?php
- // creating the post header
- thematic_postheader();
- ?>
- <div class="entry-content">
- <?php
- the_content();
- wp_link_pages("\t\t\t\t\t<div class='page-link'>".__('Pages: ', 'ip4all'), "</div>\n", 'number');
- edit_post_link(__('Edit'),'<span class="edit-link">','</span>') ?>
- </div>
- <form action="<?php the_permalink(); ?>" id="contactForm" method="post">
- <fieldset class="clear">
- <legend><?php _e('Contact our editor', 'ip4all'); ?></legend>
- <?php if(isset($emailSent) && $emailSent == true) { ?>
- <p class="success">
- <?php _e('Your email was successfully sent. We will be in touch soon.', 'ip4all'); ?>
- </p>
- <?php } ?>
- <?php if(isset($hasError) || isset($captchaError)) { ?>
- <p class="error"><?php _e('There was an error submitting the form.', 'ip4all'); ?><p>
- <?php } ?>
- <p>
- <?php _e( 'Your email address will not be published. Fields marked with <span class="required">*</span> are mandatory. ', 'ip4all' ); ?>
- </p>
- <p>
- <label for="contactName"><?php _e('Name'); ?> <span class="required">*</span></label><br />
- <input type="text" name="contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) echo $_POST['contactName'];?>" class="requiredField" />
- <?php if($nameError != '') { ?>
- <span class="error"><?php echo $nameError;?></span>
- <?php } ?>
- </p>
- <p>
- <label for="email"><?php _e('Email'); ?> <span class="required">*</span></label><br />
- <input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" class="requiredField email" />
- <?php if($emailError != '') { ?>
- <span class="error"><?php echo $emailError;?></span>
- <?php } ?>
- </p>
- <p>
- <label for="subject"><?php _e('Subject', 'ip4all'); ?></label><br />
- <input type="text" name="subject" id="subject" value="<?php if(isset($_POST['subject']) && !isset($emailSent) && $emailSent == false) echo $_POST['subject'];?>" />
- </p>
- <p>
- <label for="commentsText"><?php _e('Comment'); ?> <span class="required">*</span></label><br />
- <textarea name="comments" id="commentsText" rows="10" cols="20" class="requiredField"><?php if(isset($_POST['comments']) && !isset($emailSent) && $emailSent == false) { echo stripslashes(trim($_POST['comments'])); } ?></textarea>
- <?php if($commentError != '') { ?>
- <span class="error"><?php echo $commentError;?></span>
- <?php } ?>
- </p>
- <p>
- <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', 'ip4all'); ?></label><br />
- </p>
- <p class="screen-reader-text">
- <label for="checking"><?php _e('If you want to submit this form, do not enter anything in this field', 'ip4all'); ?></label><br />
- <input type="text" name="checking" id="checking" value="<?php if(isset($_POST['checking'])) echo $_POST['checking'];?>" />
- </p>
- </fieldset>
- <p>
- <input type="hidden" name="submitted" id="submitted" value="true" />
- <button type="submit"><?php _e('Send Message', 'ip4all'); ?></button>
- </p>
- </form>
- </div><!-- .post -->
- <?php thematic_belowpost(); ?>
- <?php
- //if ( get_post_custom_values('comments') )
- //thematic_comments_template(); // Add a key/value of "comments" to enable comments on pages!
- // calling the widget area 'page-bottom'
- get_sidebar('page-bottom');
- ?>
- </div><!-- #content -->
- <?php thematic_belowcontent(); ?>
- </div><!-- #container -->
- <?php
- // action hook for placing content below #container
- thematic_belowcontainer();
- // calling the standard sidebar
- thematic_sidebar();
- // calling footer.php
- get_footer();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment