<?php

/*

Template Name: Contact Template

*/

?>

<?php

if(isset($_POST['submitted'])) {

	if(trim($_POST['contactName']) === '') {

		echo $nameError = 'Please enter your name.';

		$hasError = true;

	} else {

		$name = trim($_POST['contactName']);

	}
	
	

	if(trim($_POST['email']) === '')  {

		$emailError = 'Please enter your email address.';

		$hasError = true;

	} else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {

		$emailError = 'You entered an invalid email address.';

		$hasError = true;

	} else {

		$email = trim($_POST['email']);

	}

	
   if(trim($_POST['website']) === ''){
	
	$websiteError = 'Please enter your website.';
	 
	 $hasError = true;
	}
	else
	{
	 $website = trim($_POST['website']);
	}
	


       if(trim($_POST['subject']) === ''){
	
	$subjectError = 'Please enter your subject.';
	 $hasError = true;
	}
	else
	{
	 $subject = trim($_POST['subject']);
	}
	



	if(trim($_POST['comments']) === '') {

		$commentError = 'Please enter a message.';

		$hasError = true;

	} else {

		if(function_exists('stripslashes')) {

			$comments = stripslashes(trim($_POST['comments']));

		} else {

			$comments = trim($_POST['comments']);

		}

	}

	

	if(!isset($hasError)) {

	    

		global $data;

	   

		$emailTo = $data['contact_email'];   

		

		if (!isset($emailTo) || ($emailTo == '') ){

			$emailTo = get_option('admin_email');

		}

		$subject = 'From '.$name;

		$body = "Name: $name \n\nEmail:$email \n\n \nWebsite: $website \n\n \nSubject: $subject \n\nMessage: $comments";

		$headers = 'From: '.$name.' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;



		wp_mail($emailTo, $subject, $body, $headers);

		$emailSent = true;

	}

	



} ?>




<?php get_header('inner'); ?>
 <?php if (have_posts()) : ?>

        <?php while (have_posts()) : the_post(); ?> 

<section class="middle row">
<div class="Mid_top Align_cent"><div class="container Gray2 OswalReg36 Letter_space2 Upparcase"><?php echo $data['contact_header'];?></div></div>

<div class="Main_mid row Offset6">
<div class="container">
<aside class="colm_1 Fl full">
<div class="Map row img">

 <?php the_content(); ?>
</div>

<form class="Contact_us row Offset1" action="<?php the_permalink(); ?>" name="contactForm"   method="post">

 <?php if(isset($emailSent) && $emailSent == true) { ?>

        <div style="text-align:left; width:100%;" class="fusion-box green none"> 

        Thanks, your email was sent successfully.

        </div>

        <?php } else { ?><?php if(isset($hasError)) { ?>

        <div style="text-align:left; width:100%;" class="fusion-box red none"> 

        Sorry, an error occured.

        </div>

        <?php }  }?> 
        
        
<div class="contact_wrapper row ">
<div class="colm_2 Fl"><input name="contactName" id="contactName" value="<?php _e('Full Name','oft_theme'); ?>" class="Input" type="text" onFocus="if(this.value=='<?php _e('Full Name','oft_theme'); ?>')this.value=''" onBlur="if(this.value=='')this.value='<?php _e('Full Name','oft_theme'); ?>' "></div> <div class="colm_2 Fr"><input name="email" id="email"  class="Input" value="<?php _e('Email','oft_theme'); ?>" type="text" onFocus="if(this.value=='<?php _e('Email','oft_theme'); ?>')this.value=''" onBlur="if(this.value=='')this.value='<?php _e('Email','oft_theme'); ?>' "></div>

</div>
<div class="contact_wrapper row ">
<div class="colm_2 Fl"><input name="website" id="website" value="<?php _e('Website','oft_theme'); ?>" class="Input" type="text" onFocus="if(this.value=='<?php _e('Website','oft_theme'); ?>')this.value=''" onBlur="if(this.value=='')this.value='<?php _e('Website','oft_theme'); ?>' "></div> <div class="colm_2 Fr"><input name="subject" id="subject"  class="Input" value="<?php _e('Subject','oft_theme'); ?>" type="text" onFocus="if(this.value=='<?php _e('Subject','oft_theme'); ?>')this.value=''" onBlur="if(this.value=='')this.value='<?php _e('Subject','oft_theme'); ?>' "></div>

</div>

<div class="contact_wrapper row "><textarea name="comments" class="Textarea" cols="" rows="" onFocus="if(this.value==this.defaultValue)this.value='';" onBlur="if(this.value=='')this.value=this.defaultValue;"><?php _e('Message','oft_theme'); ?></textarea></div>
<div class="contact_wrapper row ">
<input type="hidden" name="submitted" id="submitted" value="true" />
<input name="submitted" type="submit" value="<?php _e('Send Message','oft_theme'); ?>" class="btn_1 cont_btn">

</div>

</form>

</aside>
</div>
</div>












</section>

<?php endwhile; ?>

    <?php endif; ?>
<?php get_footer(); ?>