<?php
//cf7 New field : page name
//<div class="hide">[custom_v_post_title page-name]</div>
add_action( 'wpcf7_init', 'ds1_add_form_tag_mycustomfield' );

function ds1_add_form_tag_mycustomfield() {
    wpcf7_add_form_tag( array( 'custom_v_post_title'),
        'ds1_mycustomfield_form_tag_handler', array( 'name-attr' => true ) );
}

function ds1_mycustomfield_form_tag_handler( $tag ) {
	global $post;
	
    $tag = new WPCF7_FormTag( $tag );

    if ( empty( $tag->name ) ) {
        return '';
    }

    $atts = array();

    $class = wpcf7_form_controls_class( $tag->type );
    $atts['class'] = $tag->get_class_option( $class );
    $atts['id'] = $tag->get_id_option();

    $atts['name'] = $tag->name;
    $atts = wpcf7_format_atts( $atts );

    $p_title = (is_tax() || is_category()) ? single_cat_title( '', false ) : get_the_title($post);
    $html = sprintf( '<input type="hidden" value="'. $p_title .'" %s>', $atts );
    return $html;
}
