Thread Starter
mrdog
(@mrdog)
there were some extra char in my code that make the jam… now it works.
plaese, include this code in the NEXT VERSION of the plugin. i’t svery useful:
IN includes\CLASSES.PHP
find this lines (about line 714) :
// Special [wpcf7.remote_ip] tag
if ( 'wpcf7.remote_ip' == $matches[1] ) {
return preg_replace( '/[^0-9a-f.:, ]/', '', $_SERVER['REMOTE_ADDR']);
}
insert below this:
// Special [wpcf7.page_url] tag - by ADG
if ( 'wpcf7.page_url' == $matches[1] ) {
$pageURL = "http";
if ($_SERVER["HTTPS"] == “on”) {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
NOW YOU CAN USE in your mail message the tag [wpcf7.page_url] to insert the URL of the page WHERE the FORM was submitted.
BYES!
Good work!
I want to add the possibility to include the PAGE TITLE in the e-mail.
But unfortunately i didn´t get the post-id.
Any ideas??
// Special [wpcf7.page_title] tag
if ( 'wpcf7.page_title' == $matches[1] ) {
//$pagetitle = get_the_title(get_the_ID());
$pagetitle = "Hallo Welt: " . get_the_ID();
return $pagetitle;
}
Here is a module, which does the trick:
<?php
/**
** [pagetitle name] -> pagetitle of that post/page is available via [name]
**
**/
/* Shortcode handler */
function wpcf7_pagetitle_shortcode_handler( $tag ) {
global $wpcf7_contact_form;
if ( ! is_array( $tag ) )
return ”;
$type = $tag[‘type’];
$name = $tag[‘name’];
$html = ‘<input type=”hidden” name=”‘. $name .'” value=”‘.get_the_ID().'” />’;
return $html;
}
wpcf7_add_shortcode( ‘pagetitle’, ‘wpcf7_pagetitle_shortcode_handler’, true );
function wpcf7_pagetitle_validation_filter( $result, $tag ) {
global $wpcf7_contact_form;
$type = $tag[‘type’];
$name = $tag[‘name’];
$thePageID = (int) $_POST[$name] ;
if ( $thePageID == 0 ) {
$result[‘valid’] = false;
$result[‘reason’][$name] = ‘Someone tampered with the form! Bad guy!’;
return $result;
}
$_POST[$name] = get_the_title($thePageID);
return $result;
}
add_filter( ‘wpcf7_validate_pagetitle’, ‘wpcf7_pagetitle_validation_filter’, 10, 2 );
?>
schulzjan’s module looks nice!
This is what i´m looking for. But, sorry for the simple Question, i´m not sure what i muss do with the module from schulzjan ? insert into classes.php? yes? between witch lines ? Pleace Help me, i try this for 3 Days.
You legend!! I’ve been searching for weeks for to find this fix!
Your help is very much appreciated!!!
Thanks you
Thank you very much schulzjan !
I have modified your code in order to add hidden field with a parameter from the url, for example with http:/yousite.com/contact/?id=12 you can get ‘id’ value (12) and use it in your mail.
<?php
/**
** module, which adds a computed values to be displayed in the resulting message:
** [pagelink name] -> permalink of that post/page is available via [name]
**/
/* Shortcode handler */
function wpcf7_pagelink_shortcode_handler( $tag ) {
global $wpcf7_contact_form;
global $wp_query;
if ( ! is_array( $tag ) )
return '';
$type = $tag['type'];
$name = $tag['name'];
$url = $_SERVER['QUERY_STRING'];
parse_str($url, $query);
$html = '<input type="hidden" name="'. $name .'" value="'.$query['id'].'" />';
return $html;
}
wpcf7_add_shortcode( 'pagelink', 'wpcf7_pagelink_shortcode_handler', true );
function wpcf7_pagelink_validation_filter( $result, $tag ) {
global $wpcf7_contact_form;
$type = $tag['type'];
$name = $tag['name'];
$url = $_SERVER['QUERY_STRING'];
parse_str($url, $query);
$thePageID = $query['id'];
$_POST[$name] = $thePageID;
return $result;
}
add_filter( 'wpcf7_validate_pagelink', 'wpcf7_pagelink_validation_filter', 10, 2 );
thank you again !!! (apologies for my english)
@thoolz : you have to save schulzjan’s code as pagelink.php for example and put it in the contact-form-7’s module directory into your server.
I’ve added schulzjan’s code as pagelink.php and put it into the module directory but I’m still not sure what short code to use and where I should add it.
Any help would be really appreciated. Thanks for everyone’s help on this topic so far.
Hi dunc1,
Try to go to the admin page of contact-form7
Next put the [pagelink yourcode] short code in the form. Then use [yourcode] in the mail.
I hope this will help you
Bye
I can’t get this to work. I added the pagelink.php file to the Contact Form 7 modules directory, added the [pagelink name] to the contact form, and added [name] to the Message Body.
After I submit the form and check my email, it displays the [name] in the email.
Also, when I view the source for the hidden input field I get an empty value. Am I missing something?
jabounet,
You said to put [pagelink yourcode] in the form, and [yourcode] in the mail, but when looking at the pagelink.php file it says
** [pagelink name] -> permalink of that post/page is available via [name]
Which is correct? Do I need to change something in pagelink.php?
Hi nealb13
I’m confused, I wrote [pagelink name] but it was for the module i modified.
If you used exact schulzjan’s module put [pagetitle name] in the form and for the module i posted put [pagelink name]
The [name] is a variable, you can choose whatever you want, for example [pagetitle thepage] in the form ([thepage] in the message)
If you used the modified module, it retrieves the value of the url parameter ‘id’, try to put ?id=yyy at the end of your url (like test.com/?id=yyy) the value of the hidden field should be ‘yyy’
How anyone found this solution with
wpcf7_add_shortcode
is now broken??
Returns a “Call to undefined function” error.
Anyone know how to carry this through to the current version of contact form?
this helped me a lot but my case is kinda different, because i want to get the post title and make it appear in the email message.
i re-edited the code edited by schulzjan so here’s may code. maybe somebody might use it.
<?php
/**
** module, which adds a computed values to be displayed in the resulting message:
** [pagelink name] -> permalink of that post/page is available via [name]
**/
/* Shortcode handler */
function wpcf7_pagelink_shortcode_handler( $tag ) {
global $wpcf7_contact_form;
global $wpdb;
if ( ! is_array( $tag ) )
return '';
$type = $tag['type'];
$name = $tag['name'];
$post = get_the_ID();
$querystr = "SELECT * FROM $wpdb->posts WHERE ID = $post ";
$pageposts = $wpdb->get_row($querystr, ARRAY_A);
$html = '<input type="hidden" name="'. $name .'" value="'.$pageposts['post_title'].'" />';
return $html;
}
wpcf7_add_shortcode( 'pagelink', 'wpcf7_pagelink_shortcode_handler', true );
function wpcf7_pagelink_validation_filter( $result, $tag ) {
global $wpcf7_contact_form;
$type = $tag['type'];
$name = $tag['name'];
return $result;
}
add_filter( 'wpcf7_validate_pagelink', 'wpcf7_pagelink_validation_filter', 10, 2 );
@cutescar2nis
This is super excellent, I have been struggling to get a post name in the email and can barely contain my elation you modified this! It appears to be exactly what I need and have been searching for!
This is all and only what I have done:
I have put the file in the directory (your exact version above)as pagelink.php
I have added [pagelink name] to the generic form
I have added [name] to the email
But all that returns is “[name]” – can you advise on how to most appropriately use this wonderful gem of a function?
Many thanks
Sam