Skip Navigation

[Resolved] select a form field dropdown refering to value of another dropdown

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by alexanderW-6 1 year, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2550087

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.

#2550705

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.

#2555193

My issue is resolved now. Thank you!