Sei sulla pagina 1di 3

<?

php
/*
Template Name: Contact
*/
?>
<?php
/* Edit the error messages here ------------------------------------------------
--*/
$nameError = __( 'Please enter your name.', 'bd' );
$subjectError = __( 'Please enter a subject.', 'bd' );
$emailError = __( 'Please enter your email address.', 'bd' );
$emailInvalidError = __( 'Please enter a valid email address.', 'bd' );
$commentError = __( 'Please enter a message.', 'bd' );
/*------------------------------------------------------------------------------
--*/
$errors = array();
if(isset($_POST['submitted'])) {
if($_POST['antispam']!=''){
$hasError = true;
}
if(trim($_POST['contactName']) === '') {
$errors['nameError'] = $subjectError;
$hasError = true;
} else {
$name = trim($_POST['contactName']);
}
if(trim($_POST['contactSubject']) === '') {
$errors['subjectError'] = $subjectError;
$hasError = true;
} else {
$subject = trim($_POST['contactSubject']);
}
if(trim($_POST['email']) === '') {
$errors['emailError'] = $emailError;
$hasError = true;
} else if ( !is_email($_POST['email']) ) {
$errors['emailInvalidError'] = $emailInvalidError;
$hasError = true;
} else {
$email = trim($_POST['email']);
}
if(trim($_POST['comments']) === '') {
$errors['commentError'] = $commentError;
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['comments']));
} else {
$comments = trim($_POST['comments']);
}
}
if(!isset($hasError)) {
$emailTo = bd_get_option('user_email');
if (!isset($emailTo) || ($emailTo == '') ){
$emailTo = get_option('admin_email');
}
$sitename = get_bloginfo( 'name' );
$from = '['.$sitename.']';
$body = "<p>
<strong>Name</strong> : $name<strong></p>
<p><strong>Email</strong>: $email </p>
<strong>Message</strong>:<p>$comments</p>";
$headers = 'From: '.$from.' <'.$email.'>' . "\r\n" . 'Reply-To:
' . $email;
add_filter('wp_mail_content_type',create_function('', 'return "t
ext/html"; '));
if(wp_mail($emailTo, $subject, $body, $headers))
$emailSent = true;
else
_e('An error occured, please try again later.', 'bd');
}
}
get_header();
bd_page_before();
?>
<div class="wrap" id="main-content">
<div id="primary" class="site-content">
<div id="content" role="main">
<?php if(have_posts()): while(have_posts()): the
_post();
the_content();
if(isset($emailSent) && $emailSent == true) { ?>
<div class="thanks">
<h4><?php _e('Thanks, your email
was sent successfully.', 'bd') ?></h4>
</div>
<?php } else { ?>
<?php if(isset($hasError)) { ?>
<p class="error"><?php _e('Sorry, an err
or occured.', 'bd') ?><br>
<?php if($errors != array()): ?>
<ul>
<?php foreach($e
rrors as $k => $v): ?>
<li><?ph
p echo $v; ?></li>
<?php endforeach
; ?>
</ul>
<?php endif; ?>
<p>
<?php } ?>
<form action="<?php the_permalink(); ?>" id="con
tactForm" method="post">
<div class="contactform">
<div class="input">
<label for="contactName"
><?php _e('Your Name:', 'bd') ?></label>
<input type="text" name=
"contactName" id="contactName" value="<?php if(isset($_POST['contactName'])) ech
o $_POST['contactName'];?>" class="required requiredField" autofocus>
<div class="error-inline
"><?php echo $nameError; ?></div>
</div>
<div class="input"><label for="e
mail"><?php _e('Your Email:', 'bd') ?></label>
<input type="text" name=
"email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email']
;?>" class="required requiredField email">
<div class="error-inline
"><?php echo $emailError; ?></div>
<div class="error-inline
"><?php echo $emailInvalidError; ?></div>
</div>
<div class="input">
<label for="contactSubje
ct"><?php _e('Subject:', 'bd') ?></label>
<input type="text" name=
"contactSubject" id="contactSubject" value="<?php if(isset($_POST['contactSubjec
t'])) echo $_POST['contactSubject'];?>" class="required requiredField">
<div class="error-inline
"><?php echo $subjectError; ?></div>
</div>
<div class="input">
<textarea name="comments
" id="commentsText" class="required requiredField"><?php if(isset($_POST['commen
ts'])) { if(function_exists('stripslashes')) { echo stripslashes($_POST['comment
s']); } else { echo $_POST['comments']; } } ?></textarea>
<div class="error-inline
"><?php echo $commentError; ?></div>
</div>
<input type="hidden" id="antispa
m" name="antispam" class="hidden" value="">
<div class="buttons">
<input type="submit" nam
e="submitted" id="submitted" value="<?php _e('Send', 'bd') ?>">
</div>
</div>
</form>
<?php } ?>
<?php endwhile; endif; ?>
</div><!-- #content -->
</div><!-- #primary .site-content -->
<?php get_sidebar(); ?>
</div><!-- #main-content .wrap -->
<?php
bd_page_after();
get_footer();
?>

Potrebbero piacerti anche