Commit c1134245 authored by agnez's avatar agnez

gasap contact form test form7

parent 1ac36cc5
<p>obselethe</p>
<?php
//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 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'];
$body = 'Name:' .$name. '\n\nEmail:' .$email. '\n\nComments: \n' .$message;
//php mailer variables
$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) gasap_contact_form_generate_response("error", $not_human); //not human!
else {
//validate email
if(!filter_var($email, FILTER_VALIDATE_EMAIL))
gasap_contact_form_generate_response("error", $email_invalid);
else //email is valid
{
//validate presence of name and message
if(empty($name) || empty($message)){
gasap_contact_form_generate_response("error", $missing_content);
}
else //ready to go!
{
$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']) 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> <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
......@@ -25,6 +25,7 @@
<h3><?php echo get_the_title(); ?></h3>
<?php the_content() ?>
<?php edit_post_link( esc_html__( 'Edit gasap', 'beans_gasap' ), '<span class="edit-link">', '</span>' ); ?>
<?php echo do_shortcode( '[contact-form-7 id="150" title="Contact form 1"]' ); ?>
</li><?php
endwhile;?>
</ul>
......@@ -33,7 +34,7 @@
</div>
</div>
<div class="uk-width-1-1 uk-width-medium-1-3">
MAP here
<?php echo do_shortcode('[gmw_post_info]'); ?>
</div>
</div>
</section><?php
\ No newline at end of file
......@@ -67,24 +67,28 @@ function gasap_prodlink_add_custom_query_var( $vars ){
return $vars;
}
//TEST
//TEST http://wordpress.stackexchange.com/questions/46581/visitors-contacting-authors
/*
* Usage: in contact form 7 form area add
* [author_email unique_name]
* and in to email address add
* [unique_name]
* Usage: in contact form 7 form area add [author_email unique_name]
* and in to email address add [unique_name]
*/
//contact form 7 author email
wpcf7_add_form_tag('author_email', 'wpcf7_expert_email_shortcode_handler', true);
add_action( 'wpcf7_init', 'gasap_custom_add_shortcode_email_referent' );
function gasap_custom_add_shortcode_email_referent() {
wpcf7_add_form_tag('author_email', 'wpcf7_expert_email_shortcode_handler', true);
}
function wpcf7_expert_email_shortcode_handler($tag) {
if (!is_array($tag)) return '';
$name = $tag['name'];
if (empty($name)) return '';
global $post;
//get author email:
$author_mail = get_the_author_meta('user_email',$post->post_author);
$author_mail = get_the_author_meta('user_email',$post->post_author); //get author email:
$html = '<input type="hidden" name="' . $name . '" value="' . $author_mail . '" />';
return $html;
}
\ 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