<?php

/*

Template Name: Contact Template

*/

?>

<?php

global $data;

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 }  }?> 
        
        <?php global $data;
?>
<div class="contact_wrapper row ">
<h1 style='color:#1ab4e6;'><?php echo $data['contact_info']; ?></h1>
<br></br>
<div class="colm_2 Fl"><input name="contactName" id="contactName" placeholder="<?php echo $data['contact_fullname']; ?>" class="Input" type="text" onFocus="if(this.value=='<?php echo $data['contact_fullname']; ?>')this.value=''" onBlur="if(this.value=='')this.value='<?php echo $data['contact_fullname']; ?>' "></div> <div class="colm_2 Fr"><input name="email" id="email"  class="Input" value="<?php echo $data['contct_email']; ?>" type="text" onFocus="if(this.value=='<?php echo $data['contct_email']; ?>')this.value=''" onBlur="if(this.value=='')this.value='<?php echo $data['contct_email']; ?>' "></div>

</div>
<div class="contact_wrapper row ">

<div class="colm_2 Fl"><input name="website" id="website" value="<?php echo $data['contact_website']; ?>" class="Input" type="text" onFocus="if(this.value=='<?php echo $data['contact_website']; ?>')this.value=''" onBlur="if(this.value=='')this.value='<?php echo $data['contact_website']; ?>' "></div> <div class="colm_2 Fr"><input name="subject" id="subject"  class="Input" value="<?php echo $data['contact_subject']; ?>" type="text" onFocus="if(this.value=='<?php echo $data['contact_subject']; ?>')this.value=''" onBlur="if(this.value=='')this.value='<?php echo $data['contact_subject']; ?>' "></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 echo $data['contact_message']; ?></textarea></div>
<div class="contact_wrapper row ">
<input type="hidden" name="submitted" id="submitted" value="true" />
<input name="submitted" type="submit" value="<?php  echo $data['contact_submit']; ?>" class="btn_1 cont_btn">

</div>

</form>

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












</section>

<?php endwhile; ?>

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