custom contact form 7 tags
<?php
//contact form 7 extras
//author email
wpcf7_add_shortcode('expert_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 '';
if(isset($_GET['author_name'])) :
$curauth = get_userdatabylogin($author_name);
else :
$curauth = get_userdata(intval($author));
endif;
if (!isset($curauth->ID)){
global $wp_query;
$curauth = $wp_query->get_queried_object();
}
$html = '<input type="hidden" name="' . $name . '" value="' . $curauth->user_email . '" />';
return $html;
}
/*
* Usage: in contact form 7 form area add
* [expert_email unique_name]
* and in to email address add
* [unique_name]
*/
//sender IP
wpcf7_add_shortcode('sender_ip', 'wpcf7_sender_ip_shortcode_handler', true);
function wpcf7_sender_ip_shortcode_handler($tag) {
if (!is_array($tag)) return '';
$name = $tag['name'];
if (empty($name)) return '';
if ($_SERVER['HTTP_X_FORWARD_FOR']) {
$ip = $_SERVER['HTTP_X_FORWARD_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
$html = '<input type="hidden" name="' . $name . '" value="' . $ip . '" />';
return $html;
}
/*
* Usage: in contact form 7 form area add
* [sender_ip unique_name]
* and in to email content add
* user ip: [unique_name]
*/
//numeric only with 7 digits validation
//contact form 7 extras
//numeric only validation
wpcf7_add_shortcode('phone_validate', 'wpcf7_phone_validate_shortcode_handler', true);
function wpcf7_phone_validate_shortcode_handler($tag) {
if (!is_array($tag)) return '';
$name = $tag['name'];
if (empty($name)) return '';
$html = '<script type="text/javascript">
jQuery(document).ready(function() {
//numeric only
jQuery(".cf7_phone").keydown(function (event) {
if ((!event.shiftKey && !event.ctrlKey && !event.altKey) && ((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105))) // 0-9 or numpad 0-9, disallow shift, ctrl, and alt
{
// check textbox value now and tab over if necessary
}
else if (event.keyCode != 8 && event.keyCode != 46 && event.keyCode != 37 && event.keyCode != 39) // not esc, del, left or right
{
event.preventDefault();
}
// else the key should be handled normally
});
//validate before submit
jQuery(".wpcf7-submit").click(function(event){
var submit_ok = true;
jQuery(".phone").each(function() {
if (jQuery(this).val().length != 7){
alert("Phone Number must be 7 digits");
var submit_ok = false;
}
});
if (!submit_ok){
event.preventDefault();
return false;
}
});
});
</script>';
return $html;
}
/*
* Usage: in contact form 7 form area add
* [text class=phone]
* [phone_validate]
*/