我需要从 php 生成 CF7 字段以使表单动态化。
<div>[text* your-name]</div>
因此,我没有直接在 wordpress中编写等,而是有一个模板文件来代替。问题是这样做时,验证不起作用。字段显示正确,但提交时未检查任何字段。如果提交,则数据会正确保存。
WP ADMIN 表单选项卡:
[my_cf_template]
模板.php
<?php echo do_shortcode(apply_filters("the_content", '[contact-form-7 id="115" title="Ruumide rent - booking"]')); ?>
函数.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');
}