Ninja Forms ninja_forms_submit_data 挂钩问题
Trouble with Ninja Forms ninja_forms_submit_data hook
谁能告诉我这个 Ninja Forms 挂钩我做错了什么:
add_filter( 'ninja_forms_submit_data', 'my_ninja_forms_submit_data' );
function my_ninja_forms_submit_data( $form_data ) {
foreach( $form_data[ 'fields' ] as $field ) {
if( 'test_page_url_1519171605789' == $field['key'] ){
$current_url = "my url - {$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$field[ 'value' ] = $current_url;
}
}
$form_settings = $form_data[ 'settings' ]; // Form settings.
$extra_data = $form_data[ 'extra' ]; // Extra data included with the submission.
return $form_data;
}
我正在尝试使用键值 "test_page_url_1519171605789" 修改隐藏的表单字段,以便它包含一个 URL。
我可以使用以下代码解决此问题:
add_filter( 'ninja_forms_submit_data', 'my_ninja_forms_submit_data' );
function my_ninja_forms_submit_data( $form_data ) {
//Need to set the current URL as the previous page since
//REQUEST_URI was returning /wp-admin/admin-ajax.php
//instead of the form's actual URL.
$current_url = $_SERVER['HTTP_REFERER'];
foreach( $form_data[ 'fields' ] as $key => $field ) {
//I need to look for the field ID and not the field key
if( $key == '197' || $key == '195' || $key == '196' || $key == '179' ){
// Update the submitted field value with the URL to the previous page.
$form_data['fields'][$key]['value'] = $current_url;
}
}
// Form settings.
$form_settings = $form_data[ 'settings' ];
// Extra data included with the submission.
$extra_data = $form_data[ 'extra' ];
return $form_data;
}
谁能告诉我这个 Ninja Forms 挂钩我做错了什么:
add_filter( 'ninja_forms_submit_data', 'my_ninja_forms_submit_data' );
function my_ninja_forms_submit_data( $form_data ) {
foreach( $form_data[ 'fields' ] as $field ) {
if( 'test_page_url_1519171605789' == $field['key'] ){
$current_url = "my url - {$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
$field[ 'value' ] = $current_url;
}
}
$form_settings = $form_data[ 'settings' ]; // Form settings.
$extra_data = $form_data[ 'extra' ]; // Extra data included with the submission.
return $form_data;
}
我正在尝试使用键值 "test_page_url_1519171605789" 修改隐藏的表单字段,以便它包含一个 URL。
我可以使用以下代码解决此问题:
add_filter( 'ninja_forms_submit_data', 'my_ninja_forms_submit_data' );
function my_ninja_forms_submit_data( $form_data ) {
//Need to set the current URL as the previous page since
//REQUEST_URI was returning /wp-admin/admin-ajax.php
//instead of the form's actual URL.
$current_url = $_SERVER['HTTP_REFERER'];
foreach( $form_data[ 'fields' ] as $key => $field ) {
//I need to look for the field ID and not the field key
if( $key == '197' || $key == '195' || $key == '196' || $key == '179' ){
// Update the submitted field value with the URL to the previous page.
$form_data['fields'][$key]['value'] = $current_url;
}
}
// Form settings.
$form_settings = $form_data[ 'settings' ];
// Extra data included with the submission.
$extra_data = $form_data[ 'extra' ];
return $form_data;
}