Hey there,
I have a frontend form to add content to a RFG with some dropdowns.
The first dropdown is prepopulated with titles/Ids of a CPT A.
The second dropdown is prepopulated with taxonomy values available for the CPT A (only 1 value per post A)
What I want to achieve is that the form automatically saves the taxonomy which is assigned to the selected Post A in the dropdown when saving the RFG.
Is it possible to achieve that with the cred_before_save_data hook?
(var 1) - get ID of selected dropdown 1 in the form
(var 2) - search for the assigned taxonomy ID of (var 1) in CPT A
select (var 2) in dropdown 2 and save it into the rfg.
thanks in advance.
Hello,
No, "cred_before_save_data" can not achieve what you want.
See our document:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_before_save_data
This action hook works in server side, and is triggered after user submit the form and before save the data.
In your case, you will need to consider custom codes, for example:
1) When user choose an option in first dropdown, trigger an AJAX call:
https://codex.wordpress.org/AJAX_in_Plugins
2) In server side:
Get the post ID value of first dropdown, and get term's information by that post ID, and return it in JSON format
3) In client side, use above JSON values to update second dropdown options.
My issue is resolved now. Thank you!