<?php
/**
* Template Name: Contact Page
*
*/
?>
<?php the_post(); ?>
<?php
$error = ”;
$success = ”;
if( isset($_POST['action']) && $_POST['action']==’contact-form’ )
{
$name = $_POST['contact-name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if( $name == “” || $email == “” || $subject == “” || $message == “” ) {
$error = ‘Fields are required.’;
} else if( !filter_var($email, FILTER_VALIDATE_EMAIL) ) {
$error = ‘Invalid email address.’;
} else {
/* get admin email from database */
$to = get_option(‘admin_email’);
$headers = ‘From: “‘. $name .’” <’ . $email . ‘>’;
$mail = wp_mail( $to, $subject, $message, $headers);
if( $mail ) {
$success = ‘Message successfully sent.’;
}
}
}
?>
<?php get_header(); ?>
<div class=”contact-container”>
<div class=”content-wrapper”>
<div class=”post-<?php the_ID() ?>” class=”post”>
<div class=”entry-content”>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<div class=”message-box”>
<div class=”error-box”><?php if( $error != “” ) { echo ‘<p>’.$error.’</p>’; } ?></div>
<div class=”success-box”><?php if( $success != “” ) { echo ‘<p>’.$success.’</p>’; } ?></div>
</div>
<form action=”<?php the_permalink(); ?>” method=”post” id=”ryans_contact_form”>
<p>
<label for=”contact-name”>Name</label> <br/>
<input type=”text” name=”contact-name” id=”contact-name” value=”<?php echo (isset( $_POST['contact-name'] ) ? $_POST['contact-name'] : ”) ?>” />
</p>
<p>
<label for=”email”>Email</label> <br/>
<input type=”text” name=”email” id=”email” value=”<?php echo (isset( $_POST['email'] ) ? $_POST['email'] : ”) ?>” />
</p>
<p>
<label for=”subject”>Subject</label> <br/>
<input type=”text” name=”subject” id=”subject” value=”<?php echo (isset( $_POST['subject'] ) ? $_POST['subject'] : ”) ?>” />
</p>
<p>
<label for=”message”>Message</label> <br/>
<textarea cols=”46″ rows=”8″ name=”message” id=”message”><?php echo (isset( $_POST['message'] ) ? $_POST['message'] : ”) ?></textarea>
</p>
<input type=”submit” value=”Send” />
<input type=”hidden” name=”action” value=”contact-form”>
</form>
</div><!– end entry-content –>
</div><!– end post–>
</div><!– end content –>
<?php get_sidebar() ?>
<div class=”clear”></div>
</div><!– end container –>
<?php get_footer() ?>
|