gpt4 book ai didi

Gravity Forms Multipage Form, dynamically populate from existing form entry based on unique key(重力表单多页表单,基于唯一键从现有表单条目动态填充)

转载 作者:bug小助手 更新时间:2023-10-24 23:15:32 26 4
gpt4 key购买 nike



I'm working with Gravity Forms (WordPress) on a pair of forms for a school. They have an initial form for applications. Each submission gets assigned a unique five character key to identify it. This is saved in a hidden field. This form has things like name, email, phone, address etc. This form is up and running, working great.

我正在为一所学校制作一对表格,这是重力表格(WordPress)。他们有一份申请的初始表格。每次提交都会被分配一个唯一的五个字符的密钥来标识它。这将保存在隐藏字段中。此表单包含姓名、电子邮件、电话、地址等内容。此表单已启动并运行,运行良好。



Once a student has been accepted, we now need to have another form that is for registrations. This form will be a multipage form with more detail and various questions about history/parents etc. My thought is that the first page contains a single field that asks for the key assigned to their application. Once this first page is submitted, the form would query the database based on the key and return any info from the original application that applies to the second form. So things like name, email, phone wouldn't have to be re-entered manually.

一旦一个学生被录取,我们现在需要有另一个用于注册的表格。这个表格将是一个多页的表格,有更多的细节和关于历史/父母等的各种问题。我的想法是第一页包含一个单独的字段,要求输入分配给他们的应用程序的密钥。提交第一个页面后,表单将根据密钥查询数据库,并返回原始应用程序中适用于第二个表单的任何信息。因此,姓名、电子邮件、电话等信息不必重新手动输入。



I'm starting down the road of dynamic population and running into some trouble. It appears things operate differently on multi-page forms, and depending on whether you're using AJAX or not. Has anyone had experience doing this kind of key lookup for form population? I could do this in vanilla PHP/MySQL without a problem, but the Gravity Forms stuff has me stumped.

我开始在人口动态的道路上前进,但遇到了一些麻烦。在多页表单上的操作似乎有所不同,这取决于您是否使用AJAX。有没有人有过为表单填充执行这种键查找的经验?我可以用普通的PHP/MySQL轻松地完成这项工作,但重力表单的东西把我难住了。


更多回答
优秀答案推荐

Your question is not clear enough and is left open for interpretation. However, since I ran into problems with multi-page gravitiy forms as well, and could find very little help online, here is my experience.

你的问题不够清楚,有待解释。然而,由于我也遇到了多页重力表单的问题,并且在网上几乎找不到帮助,下面是我的经验。



If you go from one page to the next, you can access field values from previous pages using rgpost("input_" . YOUR_FIELD_ID);. Checkbox collections are accessed by "input_".FIELD_ID."_".OPTION_INDEX. Dynamically filled dropdowns seemed to get reset in my experience. If this happens to you, before moving to the next page, you can copy any values from these fields into hidden fields, and read from the hidden fields.

如果从一页转到下一页,您可以使用rgpost(“INPUT_”)访问前几页中的字段值。Your_field_ID);。CheckBox集合由“INPUT_”.FIELD_ID.“_”.OPTION_INDEX访问。在我的经验中,动态填充的下拉列表似乎得到了重置。如果发生这种情况,在转到下一页之前,您可以将这些字段中的任何值复制到隐藏字段中,并从隐藏字段中读取。



Fields that already have a default value (field->defaultValue) are NOT updated even though the appropriate hooks are triggered. E.g: add_filter('gform_field_value_my_field', 'populate_your_field'). A dump of the value you return in populate_your_field will show a different value than when you inspect my_field, which is supposed to receive this value. my_field will retain the first value it received and wont change anymore.

即使触发了适当的挂钩,已经具有缺省值的字段(field->defaultValue)也不会更新。例如:ADD_FILTER(‘GFORM_FIELD_VALUE_MY_FIELD’,‘PULATE_YOUR_FIELD’)。当您检查MY_FIELD时,转储您在PUPATE_YOUR_FIELD中返回的值将显示一个不同的值,而MY_FIELD应该接收这个值。My_field将保留它收到的第一个值,并且不会再更改。



This is a problem when your fields depend on input of fields from previous pages, and users go back and forth changing those. Your dependend fields wont update on any hook. I've tested extensively with gform_field_value, gform_pre_render, gform_field_validation and gform_post_paging.

当您的字段依赖于以前页面中的字段输入,并且用户来回更改这些字段时,这是一个问题。您的从属字段在任何挂钩上都不会更新。我已经使用gform_field_value、gform_pre_render、gform_field_valify和gform_post_paging进行了广泛的测试。



I found one solution: echo a hidden div with data attributes in the gform_pre_render hook, and populate the fields through javascript.

我找到了一种解决方案:在gformprerender钩子中使用数据属性回显一个隐藏的div,并通过javascrip填充字段。



add_filter('gform_pre_render', 'dynamic_population', 10, 1);
function dynamic_population($form) {
echo "<div id='my_data' style='display:none' data-myjsonarray='.json_encode(my_json_array).'></div>";
}

ADD_FILTER(‘GFORM_PRE_RENDER’,‘DYNAMIC_POPULATION’,10,1);函数DYNAMIC_POPULATION($FORM){ECHO“

”;=‘DISPLAY:NONE’STYLE=‘DISPLAY:NONE’STYLE}



In your gravity form, you can create a html field and add javascript in there.

在重力形式中,您可以创建一个html字段并在其中添加javascrip。



<script>
window.onload = function() {
//custom function that fills given gform dropdown with given array
fill_dropdown(
jQuery('#input_1_1'),
jQuery('#my_data').data('myjsonarray')
);
}
</script>

<脚本>window.onLoad=Function(){//使用给定的数组Fill_Dropdown(jQuery(‘#INPUT_1_1’),jQuery(‘#MY_Data’).Data(‘myjsonarray’))填充给定的Gform Dropdown的自定义函数;}



Hope this somehow helps someone.

希望这能对某个人有所帮助。



Gravity Forms Populate Anything can handle this really well.

重力形态充斥着任何可以很好地处理这一点的东西。




  1. Add a field to your form where the user would enter their reference number.

  2. Configure a field to be populated with the entry data based on the provided reference ID where it matches an entry that has the same reference ID:



    https://gwiz.io/2UByMQB




Not the best and you can use Dave's Idea, he is from Gravity Wiz, I go to that forum for help sometimes. That said, I've done this with a combination of jQuery in WordPress to grab and set the values from other fields, store the values temporarily on localStorage to store the values in, and then the gform_pre_render in WordPress for Gravity Forms to update the value on the new form. On the final step you could also make shortcodes in Wordpress for every form id you want to do this with and pass dynamic values via gform_pre_render function or pass it back from the cookie with JQuery to the field class you give it.

不是最好的,你可以用戴夫的想法,他来自重力奇才,我有时会去那个论坛寻求帮助。也就是说,我使用WordPress中的jQuery组合来获取和设置其他字段中的值,将值临时存储在本地存储上以存储值,然后使用WordPress for Grarain Forms中的gform_preRender来更新新表单上的值。在最后一步,您还可以在WordPress中为您想要使用的每个表单id编写快捷码,并通过gform_prer函数传递动态值,或者将其从带有JQuery的cookie返回给您提供的字段类。


更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com