Wordpress Contact form 7, fields in template.php - not validating correctly

550 Views Asked by At

I need to generate CF7 fields from php to make the form dynamic.

So instead of writing <div>[text* your-name]</div> and so on directly in wordpress, I have a template file that does that instead. The problem is that when doing so, the validation is not working. The fields are displayed correctly, but no fields are checked when submitting. If submitting, the data is however saved correctly.

WP ADMIN form tab:

[my_cf_template]

template.php

<?php echo do_shortcode(apply_filters("the_content", '[contact-form-7 id="115" title="Ruumide rent - booking"]')); ?>

functions.php

function cf_template_func(){

    $email = wpcf7_do_shortcode('[email* your-email]');
    $submit = wpcf7_do_shortcode( '[submit "Send"]' );

    $str = <<<HTML


    <div class="detailed-info">

        <label> Your E-mail*
        $email </label>

    </div>  
    $submit     
    HTML;
    return $str;
}

add_action( 'wpcf7_init', 'custom_add_shortcode');

function custom_add_shortcode() {
    wpcf7_add_shortcode( 'my_cf_template', 'cf_template_func');
}
0

There are 0 best solutions below