【发布时间】:2019-10-23 13:44:20
【问题描述】:
我是 WordPress 爱好者,我正在努力完成一些事情,但我还没有找到方法。
这是交易,我有一个使用 Contact Form 7 制作的表单,我想在提交表单时提取值并在 WordPress 页面的正文中使用它们作为我在提交表单时运行的脚本.
在我的functions.php上我有:
add_action('wpcf7_mail_sent','save_data_in_variables');
add_action('wpcf7_mail_failed','save_data_in_variables');
function save_data_in_variables($conference_form){
$submission = WPCF7_Submission::get_instance();
if (!$submission){
echo 'Form was not sent';
}
$posted_data = $submission->get_posted_data();
}
function wpc_vc_shortcode( $atts ) {
echo $posted_data['your-name'];
}
add_shortcode( 'name_in_the_form', 'wpc_vc_shortcode');
在页面的正文上,我运行了一个脚本,该脚本在提交表单时提交数据,但我想使用简码将值替换为表单的值:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
truestats.logEvent('Lead Conference', { id: '[name-in-the-form]' } );
}, false );
</script>
我该如何做到这一点?到目前为止,当我提交表单时没有显示任何值。
非常感谢
【问题讨论】:
标签: php wordpress function contact-form-7