php获取form传递的变量,PHP-将变量传递给Ninja Form字段
目的
以下函数应使用变量在我的表单上预填充隐藏字段(hidden_email …).
怀疑
但是,在加载页面时已经声明了我需要传递给该字段的变量“ $cust_email”.现在,它包含一个电子邮件地址.
当前结果
问题是,当下面的代码运行时,该变量似乎已经为空.什么都没有传递到表单的字段.
function create_page() {
$cust_email = $json->emailAddress;
function ninja_forms_handler() {
add_action ( 'ninja_forms_pre_process', 'add_customers_email' );
}
add_action( 'init', 'ninja_forms_handler' );
function add_customers_email() {
global $ninja_forms_processing;
$form_id = $ninja_forms_processing->get_form_ID();
if( $form_id == 3 ){
$ninja_forms_processing->update_field_settings( ‘hidden_email_1488454108179’, $cust_email );
}
}
}
解决方法:
如何使用WordPress Post Meta Value中的任何Ninja表单字段更新,填充或预填充默认值:
add_filter( 'ninja_forms_render_default_value', 'wm_the_value' , 10 , 3);
function wm_the_value( $default_value, $field_type, $field_settings ) {
if( 'textbox' == $field_type && in_array('ref' , $field_settings)){
$default_value = get_post_meta(get_the_ID(),'_listing_mls', true);
}
return $default_value;
}
ref是忍者形式的字段名称.
_listing_mls是WP数据库中用于发布后字段的meta_key名称.
标签:ninja-forms,wordpress,php
来源: https://codeday.me/bug/20191026/1934617.html
总结
以上是生活随笔为你收集整理的php获取form传递的变量,PHP-将变量传递给Ninja Form字段的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 用php写京东抢购,关于抢京东券高并发的
- 下一篇: lazarus php,Lazarus