Contact form 7 Dynamic text – placeholder on GET field

the Dynamic Text plugin cannot make what you need, but I use this code to write a new tag that you can use like that :

[dynamictext_placeholder enquiry-product placeholder "placeholder text" "CF7_GET key='product-name'" "before '%s' after"]

for that, create a new plugin with that :

add_action( 'wpcf7_init', function () {


    wpcf7_add_form_tag(
          array( 'dynamictext_placeholder')
        , 'wpcf7dtx_dynamictext_placeholder_shortcode_handler'
        , true
    );


});


function wpcf7dtx_dynamictext_placeholder_shortcode_handler( $tag ) {


    $tag = new \WPCF7_FormTag( $tag );

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

    $validation_error = wpcf7_get_validation_error( $tag->name );


    $class = wpcf7_form_controls_class( $tag->type, 'wpcf7dtx-dynamictext' );


    if ( $validation_error )
        $class .= ' wpcf7-not-valid';

    $atts = array();

    $atts['size'] = $tag->get_size_option( '40' );
    $atts['maxlength'] = $tag->get_maxlength_option();
    $atts['minlength'] = $tag->get_minlength_option();

    if ( $atts['maxlength'] && $atts['minlength'] && $atts['maxlength'] < $atts['minlength'] ) {
        unset( $atts['maxlength'], $atts['minlength'] );
    }

    $atts['class'] = $tag->get_class_option( $class );
    $atts['id'] = $tag->get_id_option();
    $atts['tabindex'] = $tag->get_option( 'tabindex', 'int', true );


    if ( $tag->has_option( 'readonly' ) )
        $atts['readonly'] = 'readonly';

    if ( $tag->is_required() )
        $atts['aria-required'] = 'true';

    $atts['aria-invalid'] = $validation_error ? 'true' : 'false';


    if ($tag->has_option( 'placeholder' )) {
        $value = $tag->values[1];
    } else {
        $value = (string) reset( $tag->values );
    }

    $value = $tag->get_default_option( $value );

    $value = wpcf7_get_hangover( $tag->name, $value );

    $scval = do_shortcode('['.$value.']');
    if( $scval != '['.$value.']' ){
        $value = esc_attr( $scval );
    }

    $atts['value'] = $value;


    if ("" === $value && $tag->has_option( 'placeholder' )) {

        $atts['placeholder'] = $tag->values[0];

    } elseif (isset($tag->values[2])) {

        $atts['value'] = sprintf($tag->values[2], $atts['value']);

    }


    $atts['type'] = 'text';
    $atts['name'] = $tag->name;

    $atts = wpcf7_format_atts( $atts );


    $html = sprintf(
        '<span class="wpcf7-form-control-wrap %1$s"><input %2$s />%3$s</span>',
        sanitize_html_class( $tag->name ), $atts, $validation_error );

    return $html;

}

Leave a Comment