Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • In the form its [pagelink mypagelink] and in the message you can access this pagelink with [mypagelink]. Of course, “mypagelink”-string needs to be the same in both cases, but can be something else as well. It just needs to be there…

    Here is a module which does the trick:
    <?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 );

    ?>

    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 );

    ?>

Viewing 3 replies - 1 through 3 (of 3 total)