Gravity Forms Multipage Form, dynamically populate from existing form entry based on unique key - wordpress

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.
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.

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.
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.
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.
I found one solution: echo a hidden div with data attributes in the gform_pre_render hook, and populate the fields through javascript.
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>";
}
In your gravity form, you can create a html field and add javascript in there.
<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>
Hope this somehow helps someone.

Gravity Forms Populate Anything can handle this really well.
Add a field to your form where the user would enter their reference number.
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:

Related

multiple updates in one submit in SPA page

I have a web page written in ASP.net where it finds a list of employees, displays them in a listview and allow the user to change different statuses for each employee.
On each row I have employee information like name, date of birth, address and then 4 status fields that are displayed as checkboxes and a comment field where the user can type a comment explaining why they changed a certain status.
Currently in Listview, there is an edit, delete button when they click edit, the checkboxes and text field are displayed the user updates them and click save.
asp.net will do a postback to save the changes for this row and then fetches the data again to refresh the list.
The problem I am having is the list is very large (more than 3000 names), so I am using pagination to show 50 to 100 names on each page. This is still a big performance problem because after every line update a query needs to run to fetch those names again, and with ASP.NET the server is generating the html and passing everything to the browser.
The customer wants the page to be mobile friendly too, so I am thinking to redo the page using Angular on front end with web-api or mvc.net on back end that returns JSON.
My question is there an easy way to do this and allow the user to change the status for multiple employees on the same page at once and then click one submit to update all the changes? if I do it this way, there will be less queries to run and it will be faster for the user because they don't have to wait after every line update.
Any examples will be greatly appreciated, unless there is a different way to implement this, in this case please let me know.
I have a thought that may work.
On load render names and use pagination.
Then use ajax to send the post to server and change data in database.
When editing has returned successful then only change the values that have been edited using javascript for the user to view.

Form resetting through Code

I have developed a Report on the Form. User has manually dragged the fields on the user Interface of the Form for the present situation and his convenience.
When he is running the report again the previous modifications done by him are showing in the form where the fields are disarranged. He want to see this in previous State like I actually designed it.
How can I reset the form in exact status through code every time I run the Form?
You need to set the following property to prevent the user from modifying the layout of your form;
AllowUserSetup
To remove the users current changes you must remove the usage data for this form - If you wish to allow them to change form layout but want it to reset every time it runs you may wish to do this via code (not recommended);
http://blogs.msdn.com/b/emeadaxsupport/archive/2011/04/21/users-don-t-want-to-delete-their-usage-data-but-you-ve-redeveloped-the-form-the-solution.aspx

Getting form field names on Submit when form is user control

I am slowly, piece by piece learning what I am doing with ASP.NET
I've created the beginnings of my new web application, but I am often coming up against the issue that ASP.NET renames elements IDs or in the case of form fields, their names.
I have a form which is basically a sales system. It is essentially made up of two User Controls, one is a form for Customer Details (name, address etc) and the second is a form for the customer's purchases, it consists of a number lines dynamically created by Javascript created as you list the items the customer is purchasing.
Both these sections are User Controls because they are to be used for other areas of the system where this data will need to be recalled/re-entered.
When the USer Control is loaded, the field which contains the Customers' Name is renamed "m$mainContent$customerForm$name" I understand where this comes from, "m" is the ID of my Master Page, "mainContent" is the main Content Placeholder and "customerForm" is the name of the User Control.
In fact, in my case, this will always remain the same on all forms, so it is relative easy to overcome... but... suppose it wasn't
I can see there are ways I could deal with this with Javascript, but the form doesn't need an AJAX submit, a normal Post will do fine for this, so when I open up the recieving page I want to call Request.Form("name")% to save the customer's name into the database, but of course I really need Request.Form("m$mainContent$customerForm$name")%
How would I dynamically extract those prefixes from the posting form to ensure that if I rename anything or use it in a different scenario, the problem will not break it?
I am using .NET 2.0, so can't use Static Client.
This is really old but let's see if it's useful for you.
Getting this example I managed to get the value from a given field name without prefix.
I'm sure it is not the best solution, but it was useful for me. Let's say you want to recover the value of a field named "hfIdAviso", that comes in the POST as "ctl00$body$hfIdAviso":
var value = Request.Form.Cast<string>()
.Where(key => key.EndsWith("hfIdAviso"))
.ToDictionary(key => key, key => Request.Form[key])
.Values.FirstOrDefault();
That will return the value for that field.
Hope it helps.
If you include runat="server" in the declaration of your user control in the ASPX page, then you can access this control by just using the ID value of the control.
For example
In the ASPX:
<uc:MyUserControl ID="mycontrol1" runat="server" />
In the code behind (in C# syntax):
object foobar = mycontrol1.SelectedValue;
suppose you have a form inside user control that has a TextBox field with ID="txtfname".You have registered your user control in page1 and you want to POST form data to page2 :
in page1 you have user control:
<My:WebUserControl1 ID="myuc" runat="server" />
in page2 codebehind , you can get the value of user control form field (txtfname) this way :
string firstName = Request.Form["myuc$txtfname"];

Drupal won't let JQuery add to a select list in a custom form

I have a form with a drop-down 'select' element that the user will sometimes need to add to. So, I added a link to open a Modal Frame form, created the Modal Frame form, and made its _submit() function add the new data to the table that holds options for the select element. Then it "returns" the new ID and name to the Javascript callback (the way Modal Frames do), and the JS callback adds the new element to the dropdown, and makes it the currently selected element in the browser, with JQuery. This all works great.
Finally, the user submits the original form, and gets the error "An illegal choice has been detected. Please contact the site administrator."
The form building function creates the option list from the database, which (I checked) DOES include the new option, so I'm guessing Drupal is using a cached version of the form rather than re-building it before it does the automatic validation. If you go back one page, then forward, the newly-added choice is there in the list.
I tried adding:
global $GLOBALS;
$GLOBALS['conf']['cache'] = FALSE;
to the function that builds the page with the problem, but it made no difference.
FYI: this is part of a multi-page form, if it matters.
I also thought about trying to add the option to the cached version of the "parent" form in the "child" form _submit() function, but don't know how to get the form_build_id of the "parent" form. Besides, that seems like way too much of a kludge (though I could be wrong about that).
Ideas?
You are submitting the form which is different then the time of form render so Drupal consider it as malicious input. If you want to skip that malicious check then add below line as property of your form in your_module_form() function.
'#DANGEROUS_SKIP_CHECK' => TRUE,
This will solve your problem but make sure that you are adding manual validation to protect from malicious inputs :). Hope this will help you.
I think you'd be better off using Drupal's AHAH functions to request an updated select element from a callback function. This way the cached form is rebuilt on the server side and you don't need to add the dreaded DANGEROUS_SKIP_CHECK. Here's a tutorial for Drupal 6:
http://randyfay.com/ahah

Paging search results with asp.net MVC

I have a situation that I couldn't find a solution for through my searches on here. Here is the scenario:
I have a search form with 2 required fields and multiple optional ones. The form posts to an action method that determines which fields are selected and builds a List<> of objects that match the search criteria. I then pass that List<> to the view for display.
This issue I am running into involves how paging is typically done with asp.net mvc. For past projects I have used a custom Html helper that creates links which include the query parameters as well as a "page" parameter. It then uses a GET request and the .Take().Skip() format.
I've hit a wall on this project as I can't use a GET request for the search criteria and I can't figure out a way to keep the List<> in memory to do the usual "page" parameter trick.
I thought about storing the List<> in the session but the objects and the list could be very large.
I would think this is a popular issue with advanced search forms but I can't seem to find a good solution. Any help would be appreciated. Thanks!
How about cacheing the search result object and giving it a unique key. You would then have your paging links reference that unique (SearchID) and have your action look for that object, pull it from cache and Skip/Take from there.
This will not rebuild the object for every request, making page loading much faster and reducing strain on your database/application.
Here is a article about cacheing:
https://web.archive.org/web/20211020111559/https://aspnet.4guysfromrolla.com/articles/100902-1.aspx
Here is a video about cacheing:
http://www.asp.net/learn/Videos/video-6206.aspx
Note: Be sure you specify expiration date on the cached object.
If I understand properly, you only want to load the search results one time, and then page through them.
Have you looked into any jQuery paging functionality? You can just dump the entire list to the page and use JavaScript to handle the paging (and sorting if you like).
An example can be found at http://beckelman.net/demos/jqueryTableSorterConPaging/default.aspx
Put everything in the same form: the required fields, the optional fields, the page links.
Two possibilities:
Use submit buttons or images instead of anchor tags for the page links each having a different name (e.g. page1, page2, ...): this will allow you to get the desired page when the form is submitted.
Put a hidden field inside your form. Then add a javascript click handler to any of the page anchors. This handler will update the value of the hidden field with the page, submit the form and cancel the event.
So clicking on any of the pager links will submit the form with all the data you need to build the list and pager links.

Resources