I’m really pleased with this solution, but I can’t make it work. I get a CF Validation Error when I send the form. I did everything like described above.
That’s the code in pagelink.php:
<?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;
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( 'pagelink', 'wpcf7_pagelink_shortcode_handler', true );
function wpcf7_pagelink_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_permalink($thePageID);
return $result;
}
add_filter( 'wpcf7_validate_pagelink', 'wpcf7_pagelink_validation_filter', 10, 2 );
?>
That’s my form:
<p>Tu nombre<br />
[text your-name 20/50] </p>
<p>Tu email<br />
[email your-email 20/50] </p>
<p>Email de tu amigo<br />
[email friend-email 20/40] </p>
[pagelink mypagelink]
<p>Tu mensaje<br />
[textarea your-message 20x5] </p>
<p>[submit "Enviar"]</p>
Are the tags inserted correctly like this?
And finally that’s the message body:
Haz click en este enlace para ir a la pagina: [mypagelink]
Any ideas?
Thanks