• Resolved diliescu

    (@diliescu)


    <input type=”text” name=”text-420″ value=”<?php the_ID(); ?>” size=”40″ class=”wpcf7-form-control wpcf7-text” aria-invalid=”false”>

    I have this code above, but the output value is literally <?php the_ID(); ?> instead of a set of numbers. If I write this code in a php file, I get a set of numbers (which is what I want), but when using the wordpress CF7 interface, it sees it as plain text.
    Any way I can solve this? Hope I was clear enough.

    Thx!

Viewing 4 replies - 1 through 4 (of 4 total)
  • you can do this simply passing a value with the wpcf7 shortcode

    https://contactform7.com/getting-default-values-from-shortcode-attributes/

    Thread Starter diliescu

    (@diliescu)

    @codekraft Hi!

    I’m not sure what I’m doing wrong, but it doesn’t seem to work. Could you guide me further?

    Ok so what I have now:

    CF7 form: [text text-750 customID default:shortcode_attr]
    My theme’s function: `function custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
    $my_attr = ‘customID’;

    if ( isset( $atts[$my_attr] ) ) {
    $out[$my_attr] = $atts[$my_attr];
    }

    return $out;
    } `

    and lastly: <?php echo do_shortcode(‘[contact-form-7 id=”457″ title=”Adoption Form” customID=”<?php the_ID();”]’); ?>

    Nothing seems to happen tho so I must be doing something wrong

    check the php syntax
    <?php echo do_shortcode(‘[contact-form-7 id=”457″ title=”Adoption Form” customID=”<?php the_ID();”]’); ?>
    change to
    <?php echo do_shortcode('[contact-form-7 id=”457″ title=”Adoption Form” customID=”'. the_ID() . '”]'); ?>

    this is wrong (doubled php open tag):
    <?php echo "text=<?php the_ID() ?>" ?>;

    this is correct:
    <?php echo "text='" . the_ID(); . "'" ?>;

    Thread Starter diliescu

    (@diliescu)

    @codekraft Thank you good sir. It worked eventually!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Insert some PHP inside a field value’ is closed to new replies.