Commit 5cc99b78 authored by agnez's avatar agnez

contact gasap WIP + 3 prod

parent ee1d6346
......@@ -2,75 +2,74 @@
//test https://premium.wpmudev.org/blog/how-to-build-your-own-wordpress-contact-form-and-why/?utm_expid=3606929-94.Ie3dH-CaRwe6MU3VrZsdvw.0
//response generation function
$response = "";
//function to generate response
function generate_response($type, $message){
function gasap_contact_form_generate_response($type, $message){
global $response;
if($type == "success") $response = "<div class='success'>{$message}</div>";
else $response = "<div class='error'>{$message}</div>";
}
//response messages
$not_human = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid = "Email Address Invalid.";
$message_unsent = "Message was not sent. Try Again.";
$message_sent = "Thanks! Your message has been sent.";
//user posted variables
$name = $_POST['message_name'];
$email = $_POST['message_email'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];
//response messages
$not_human = "Human verification incorrect.";
$missing_content = "Please supply all information.";
$email_invalid = "Email Address Invalid.";
$message_unsent = "Message was not sent. Try Again.";
$message_sent = "Thanks! Your message has been sent.";
//user posted variables
$name = $_POST['message_name'];
$email = $_POST['message_email'];
$message = $_POST['message_text'];
$human = $_POST['message_human'];
$body = 'Name:' .$name. '\n\nEmail:' .$email. '\n\nComments: \n' .$message. ';
//php mailer variables
$to = get_post_meta( get_the_ID(), 'gasap_mailreferent', true );
$bcc = get_option('admin_email');
$subject = "Someone sent a message from ".get_bloginfo('name');
$headers = 'From: '. $email . "\r\n" .
$to = get_option('admin_email');
$subject = "Someone sent a message from ".get_bloginfo('name');
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
if(!$human == 0){
if($human != 2) generate_response("error", $not_human); //not human!
if($human != 2) gasap_contact_form_generate_response("error", $not_human); //not human!
else {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
generate_response("error", $email_invalid);
gasap_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
generate_response("error", $missing_content);
gasap_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$sent = mail($to, $subject, $message, $headers);
if($sent) generate_response("success", $message_sent); //message sent!
else generate_response("error", $message_unsent); //message wasn't sent
$sent = wp_mail($to, $subject, strip_tags($body), $headers);
if($sent) gasap_contact_form_generate_response("success", $message_sent); //message sent!
else gasap_contact_form_generate_response("error", $message_unsent); //message wasn't sent
}
}
}
}
else if ($_POST['submitted']) generate_response("error", $missing_content);
?>
else if ($_POST['submitted']) gasap_contact_form_generate_response("error", $missing_content);
?>
<div id="respond">
<?php echo $response; ?>
<form action="<?php the_permalink(); ?>" method="post">
<p><label for="name">Name: <span>*</span></label> <br><input type="text" id="message_name" value="<?php echo esc_attr($_POST['message_name']); ?>"></p>
<p><label for="message_email">Email: <span>*</span></label> <br><input type="text" id="message_email" value="<?php echo esc_attr($_POST['message_email']); ?>"></p>
<p><label for="message_text">Message: <span>*</span></label> <br><textarea type="text" id="message_text"><?php echo esc_textarea($_POST['message_text']); ?></textarea></p>
<p><label for="message_human">Human Verification: <span>*</span></label> <br><input type="text" style="width: 60px;" id="message_human"> + 3 = 5</p>
<input type="hidden" id="submitted" value="1">
<p><input type="submit"></p>
</form>
</div>
<div id="respond">
<?php echo $response; ?>
<form action="<?php the_permalink(); ?>" method="post">
<p><label for="name">Name: <span>*</span> <br><input type="text" name="message_name" value="<?php echo esc_attr($_POST['message_name']); ?>"></label></p>
<p><label for="message_email">Email: <span>*</span> <br><input type="text" name="message_email" value="<?php echo esc_attr($_POST['message_email']); ?>"></label></p>
<p><label for="message_text">Message: <span>*</span> <br><textarea type="text" name="message_text"><?php echo esc_textarea($_POST['message_text']); ?></textarea></label></p>
<p><label for="message_human">Human Verification: <span>*</span> <br><input type="text" style="width: 60px;" name="message_human"> + 3 = 5</label></p>
<input type="hidden" name="submitted" value="1">
<p><input type="submit"></p>
</form>
</div>
<?php
wp_reset_postdata();
\ No newline at end of file
<section id="3producteurs" class="uk-block largeur1">
<?php
$do_not_duplicate = array();
$active_prod = get_query_var( 'choix_prod' );
$href = get_page_link(). '#presentation_producteur';
$loop = new WP_Query( array(
'post_type' => 'producer',
'order_by' => 'rand',
'posts_per_page' => '2'
'posts_per_page' => '2',
'post__not_in' => array( $active_prod )
));
?><div class="uk-grid"><?php
while ( $loop->have_posts() ) : $loop->the_post();
?><div class="uk-width-1 uk-width-medium-1-2"><?php
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="uk-width-1 uk-width-medium-1-2"><?php
if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
<h2><?php echo get_the_title(); ?></h2>
<?php echo get_the_term_list( get_the_ID(), 'producertype', '<div>', ', ', '</div>' ); ?>
<a class="uk-button uk-button-success" href="<?php get_permalink(); ?>"><?php esc_html_e( 'Discover', 'beans_gasap' ); ?></a>
<a class="uk-button uk-button-success" href="<?php echo esc_url( add_query_arg( 'choix_prod', get_the_ID(), $href ) )?>"><?php esc_html_e( 'Discover', 'beans_gasap' ); ?></a>
<?php edit_post_link( esc_html__( 'Edit producer', 'beans_gasap' ), '<span class="edit-link">', '</span>' ); ?>
</div>
<?php $do_not_duplicate[] = get_the_ID();
endwhile;
?></div><?php
if(get_query_var($active_prod) !== '') {
$loop2 = new WP_Query( array( 'p' => $active_prod) );
} else {
$loop2 = new WP_Query( array(
'post_type' => 'producer',
'order_by' => 'rand',
'posts_per_page' => 1,
'post__not_in' => $do_not_duplicate
));
}
while ( $loop2->have_posts() ) : $loop2->the_post();
?>
<div class="uk-block">
<div id="presentation_producteur" class="uk-block">
<div class="uk-grid">
<div class="uk-width-1 uk-width-medium-1-2">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } ?>
</div>
<div class="uk-width-1 uk-width-medium-1-2">
<h2><?php the_title(); ?></h2>
<?php the_excerpt() ?>
<a class="uk-button uk-button-success" href="<?php get_permalink(); ?>"><?php esc_html_e( 'Discover', 'beans_gasap' ); ?></a>
<?php the_content() ?>
<?php edit_post_link( esc_html__( 'Edit producer', 'beans_gasap' ), '<span class="edit-link">', '</span>' ); ?>
</div>
</div>
......@@ -48,4 +56,7 @@
?>
</section>
<?php
wp_reset_postdata();
\ No newline at end of file
wp_reset_postdata();
......@@ -59,3 +59,9 @@ function gasap_post_edit_link() {
//add edit link for post content
edit_post_link( esc_html__( 'Edit', 'beans_gasap' ), '<span class="edit-link">', '</span>' );
}
add_filter( 'query_vars', 'gasap_prodlink_add_custom_query_var' );
function gasap_prodlink_add_custom_query_var( $vars ){
$vars[] = "choix_prod"; //pour template part three_producers
return $vars;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment