|
<?php |
|
/** |
|
* The template for displaying the contact page. |
|
* |
|
* @link https://codex.wordpress.org/Template_Hierarchy |
|
* |
|
*/ |
|
while ( have_posts() ) : the_post(); ?> |
|
|
|
|
|
<div> |
|
|
|
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> |
|
|
|
<h1><?php the_title( '<h1 class="entry-title">', '</h1>' ); ?></h1> |
|
|
|
<div class="entry-content"> |
|
<?php the_content(); ?> |
|
</div> |
|
|
|
<div class="entry-content"> |
|
|
|
<div id="alert" role="alert"></div> |
|
|
|
<form class="contact-form" action="/wp-admin/admin-ajax.php" method="post"> |
|
<input type="hidden" name="action" value="contactEmail" /> |
|
<input type="hidden" name="_token" value="<?php echo csrf() ?>" /> |
|
<div class="form-group"> |
|
<label for="name">Name</label> |
|
<input type="text" class="form-control" id="name" name="name" placeholder="Name"> |
|
</div> |
|
|
|
<div class="form-group"> |
|
<label for="email">Email</label> |
|
<input type="text" class="form-control" id="email" name="email" placeholder="Email"> |
|
</div> |
|
|
|
<div class="form-group"> |
|
|
|
<label for="message">Message</label> |
|
<textarea class="form-control" name="message" placeholder="Message"> </textarea> |
|
</div> |
|
|
|
<div class="form-group"> |
|
<div class="g-recaptcha" data-sitekey="xyz"></div> |
|
</div> |
|
|
|
<div class="form-group"> |
|
<button type="submit" class="btn btn-default">Send</button> |
|
</div> |
|
|
|
</form> |
|
|
|
</div><!-- .entry-content --> |
|
|
|
</article><!-- #post-## --> |
|
</div> |
|
|
|
|
|
<?php endwhile; // End of the loop. ?> |
|
|
|
<script src='https://www.google.com/recaptcha/api.js'></script> |
|
|
|
<script type="text/javascript"> |
|
$(document).ready(function() { |
|
|
|
$('.contact-form').submit(function(e) { |
|
e.preventDefault(); |
|
|
|
|
|
|
|
var data = $('.contact-form').serialize(); |
|
var $alert = $('#alert'); |
|
|
|
var captchResponse = $('#g-recaptcha-response').val(); |
|
if (captchResponse.length == 0 ){ |
|
$alert.text('Please fill all the fields').removeClass().addClass('alert alert-danger'); |
|
return; |
|
} |
|
|
|
|
|
$.ajax({ |
|
type: 'POST', |
|
url: '/wp-admin/admin-ajax.php', |
|
data: data, |
|
success: function( data ) { |
|
var response = jQuery.parseJSON(data); |
|
|
|
if (response.status != 200) { |
|
$alert.text(response.message).removeClass().addClass('alert alert-danger'); |
|
return; |
|
} |
|
|
|
$alert.text(response.message).removeClass().addClass('alert alert-success'); |
|
} |
|
}); |
|
return false; |
|
}); |
|
}); |
|
</script> |