submit to ninja form programmatically

那年仲夏 提交于 2019-12-08 04:16:22

问题


I've been researching for days and all I want to be able to do is create entries in the ninja form admin listings. Either by submitting custom form (not ninja form generated) or just calling a hook and passing data (data will match actual form fields created in ninja form).

I want to be able to do this so that I can create any type of form layout and still be able to submit to ninja form entry. Or if anyone has any other information on a plugin that can allow me to do such a thing, please share.


回答1:


In NinjaForms version 3, you probably want to look at this file:

ninja-forms/includes/Actions/Save.php

The process function contains the important bits that may help you:

$sub = Ninja_Forms()->form( $form_id )->sub()->get();

foreach($fields as $field_id => $field_value){
    $sub->update_field_value( $field_id, $field_value );
}

$sub->save();

In NinjaForms version 2, it is a little different

$sub_id = Ninja_Forms()->subs()->create( $form_id );

foreach( $form_fields as $field_id => $value ) {

    Ninja_Forms()->sub( $sub_id )->add_field( $field_id, $value );
}

Where the $form_fields array would look like:

$form_fields = array(

    $fiel_id_1 => $value_1,
    $fiel_id_2 => $value_2,
    ...

);


来源:https://stackoverflow.com/questions/46853980/submit-to-ninja-form-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!