Ninja Forms API - 无法使用 ninja_forms_submit_data 过滤器更新字段值
Ninja Forms API - Can't update field value using ninja_forms_submit_data filter
我正在使用此代码遍历字段:
add_filter( 'ninja_forms_submit_data', function ( $form_data ) {
$form_model = Ninja_Forms()->form( $form_data[ 'id' ] );
foreach( $form_data[ 'fields' ] as $field ){
$field_model = $form_model->get_field( $field[ 'id' ] );
$field_key = $field_model->get_setting( 'key' );
if( 'subject_test' == $field_key ){
$field_model->update_settings( 'value', 'foo' )->save();
}
}
return $form_data;
} );
subject_test 是我要更改值的字段的键。
我尝试了许多其他方法来更改值,但似乎没有任何效果。
谁能指出我正确的方向?
知道了!
$form_data[ 'fields' ][ $field_id ][ 'value' ] = 'foo';
@Lee 这是我使用的完整功能:
// Change email_admin based on subject using a hidden field
add_filter( 'ninja_forms_submit_data', function ( $form_data ) {
$form_model = Ninja_Forms()->form( $form_data[ 'id' ] );
foreach( $form_data[ 'fields' ] as $field ) { // Loop through fields
$field_model = $form_model->get_field( $field[ 'id' ] );
$field_key = $field_model->get_setting( 'key' );
$field_id = $field[ 'id' ];
if( 'subject_value' == $field_key ) {
$subject_value = '';
$subject_value = $form_data[ 'fields' ][ $field_id ][ 'value' ]; // Take subject dropdown value.
$email_redirect = get_string_between($subject_value, '{', '}'); // Get email from subject value.
$new_subject = delete_all_between($subject_value, '{', '}'); // Remove {email} from subject value.
$form_data[ 'fields' ][ $field_id ][ 'value' ] = $new_subject; // Assign new subject value.
} elseif ( 'subject_send' == $field_key ) {
if ( isset($email_redirect) )
$form_data[ 'fields' ][ $field_id ][ 'value' ] = $email_redirect; // Give hidden field the email which is used in send to field.
} else {
continue;
}
}
return $form_data;
} );
我正在使用此代码遍历字段:
add_filter( 'ninja_forms_submit_data', function ( $form_data ) {
$form_model = Ninja_Forms()->form( $form_data[ 'id' ] );
foreach( $form_data[ 'fields' ] as $field ){
$field_model = $form_model->get_field( $field[ 'id' ] );
$field_key = $field_model->get_setting( 'key' );
if( 'subject_test' == $field_key ){
$field_model->update_settings( 'value', 'foo' )->save();
}
}
return $form_data;
} );
subject_test 是我要更改值的字段的键。
我尝试了许多其他方法来更改值,但似乎没有任何效果。
谁能指出我正确的方向?
知道了!
$form_data[ 'fields' ][ $field_id ][ 'value' ] = 'foo';
@Lee 这是我使用的完整功能:
// Change email_admin based on subject using a hidden field
add_filter( 'ninja_forms_submit_data', function ( $form_data ) {
$form_model = Ninja_Forms()->form( $form_data[ 'id' ] );
foreach( $form_data[ 'fields' ] as $field ) { // Loop through fields
$field_model = $form_model->get_field( $field[ 'id' ] );
$field_key = $field_model->get_setting( 'key' );
$field_id = $field[ 'id' ];
if( 'subject_value' == $field_key ) {
$subject_value = '';
$subject_value = $form_data[ 'fields' ][ $field_id ][ 'value' ]; // Take subject dropdown value.
$email_redirect = get_string_between($subject_value, '{', '}'); // Get email from subject value.
$new_subject = delete_all_between($subject_value, '{', '}'); // Remove {email} from subject value.
$form_data[ 'fields' ][ $field_id ][ 'value' ] = $new_subject; // Assign new subject value.
} elseif ( 'subject_send' == $field_key ) {
if ( isset($email_redirect) )
$form_data[ 'fields' ][ $field_id ][ 'value' ] = $email_redirect; // Give hidden field the email which is used in send to field.
} else {
continue;
}
}
return $form_data;
} );