• Picking up where this post left off:

    https://www.ads-software.com/support/topic/plugin-contact-form-7-add-custom-field-management?replies=7

    I have a ‘was this page useful’ form in the footer of a website and wanted to included the page/post title in the returned form.

    1. Include the below code in your themes ‘functions.php’

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

    2. Then in your form include the following [pagelink yourcode] shortcode. It will be hidden on the visible form.

    3. Include the following shortcode [yourcode] in your mail.

    https://www.ads-software.com/extend/plugins/contact-form-7/

  • The topic ‘[Plugin: Contact Form 7] How to add a Page/Post Title to Returned Form’ is closed to new replies.