WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Use Contact Form to gather a page title (2 posts)

  1. SRay
    Member
    Posted 3 years ago #

    Hello!

    If there's a way to make this work, it will be really powerful.

    THE TASK: I want to have the contact form quietly gather the page title or post title and report it in the email it sends to me. I have been tinkering with this code and cannot manage to figure it out.

    (I have no idea why, but the previous thread where we were discussing this has been closed even though there's still evident confusion here. (http://wordpress.org/support/topic/plugin-contact-form-7-add-custom-field-management?replies=7#post-1226523) I need to keep this discussion going actually, thanks.)

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

    Any ideas out there?

  2. SRay
    Member
    Posted 3 years ago #

Topic Closed

This topic has been closed to new replies.

About this Topic