I am working on a form for client and we require to populate a Checkboxes Field dynamically based on the results of an AJAX query, which is made based on selections of other fields in the form.
Based on the AJAX results I empty() the GravityForms checkboxes field container and rebuilt it with the desired options (there can be 1 to n checkboxes and each will have a new label I can only construct once the AJAX completed.
While this all works nicely, it seems GravityForms fully clears out that input on submit, in fact the POSTed data doesn’t even feature this input and the form entry neither. Nor is it saved in the database.
I guess my question is how to populate a checkboxes field dynamically, not with the PHP hook on form load based on data we have when the form is loaded, but based on data retrieved from the site via AJAX
In short, user selects a date in the form, I make an AJAX query and get entries by that date, populate checkboxes based on these results.
Is that even possible with GF? Admittedly doing this in full custom code would have saved me the hassle to discover it (GF) seems to just clear out any non “known” options in the checkbox lol.
I’ll assume it still needs existing options to populate.
I don’t have existing options.
The checkboxes are built depending on a set of ever changing data. Inclusive but not limited to user input.
If an add on could do it I’m sure it’s be possible with code too, and since according previous reply the options need to be available before rendering to be populated dynamically, that’ll not work either.
The data I’m building the checkboxes with is only partially available in the database (as potentially changing options and a “booking status”) and partially depends on the current user input.
I could easily prepopulate with php of course but as said I need the data pulled in real time (thus why Ajax on user input change)
To give it context:
I’ve options for each week day with opening times and available slots which can be different for each day and can change intermittently
I’ve bookings coming in using up slots
as the user chooses a day I’ll need to show him options to book
if he changes day I’ll need to update options dynamically
if the user chooses a slot, for other users that option has to be decreased or disappear or be disabled
This is why I need to pull availability per day depending on the users choice of day.
Which I won’t know up and until the user makes that choice.