Ninja Forms API - 无法使用ninja_forms_submit_data过滤器更新字段值

时间:2018-02-16 00:51:44

标签: wordpress forms filter ninja-forms

我正在使用此代码遍历字段:

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是我想要更改值的字段的关键。

我已尝试过许多其他方法来改变价值,但似乎没有任何效果。

有人能指出我正确的方向吗?

2 个答案:

答案 0 :(得分:0)

知道了!

$form_data[ 'fields' ][ $field_id ][ 'value' ] = 'foo';

答案 1 :(得分:0)

@Lee这是我使用的全部功能:

listoftensites = listoftensites
pool = Pool(processes=10) # Initalize a pool of 10 processes
listoftextis, listofonline = zip(*pool.map(onionrequestthreaded, listoftensites)) # Use the pool to run the function on the items in the iterable
print("failed to close ")
pool.close()
 # this means that no more tasks will be added to the pool
pool.join()