以编程方式提交到忍者表单 [英] submit to ninja form programmatically
问题描述
我已经研究了好几天,我想做的就是在 ninja 表单管理列表中创建条目.通过提交自定义表单(不是生成 ninja 表单)或只是调用一个钩子并传递数据(数据将匹配在 ninja 表单中创建的实际表单字段).
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).
我希望能够做到这一点,以便我可以创建任何类型的表单布局,并且仍然能够提交到 ninja 表单条目.或者如果有人有任何其他关于插件的信息可以让我做这样的事情,请分享.
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.
推荐答案
在 NinjaForms 版本 3 中,您可能想看看这个文件:
In NinjaForms version 3, you probably want to look at this file:
ninja-forms/includes/Actions/Save.php
process
函数包含可能对您有帮助的重要部分:
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();
在 NinjaForms 版本 2 中,有点不同
$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 );
}
$form_fields 数组的位置:
Where the $form_fields array would look like:
$form_fields = array(
$fiel_id_1 => $value_1,
$fiel_id_2 => $value_2,
...
);
这篇关于以编程方式提交到忍者表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!