Skip Navigation

[Resolved] Update value of field with AJAX

This support ticket is created 2 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

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/Karachi (GMT+05:00)

This topic contains 3 replies, has 3 voices.

Last updated by Waqar 2 years, 11 months ago.

Assisted by: Waqar.

Author
Posts
#2401745
Screenshot 2022-06-21 145544.png
Screenshot 2022-06-21 145530.png
Screenshot 2022-06-21 144629.png

Tell us what you are trying to do?
How to make value of "add people" automatically updated without refreshing the page after I submit new data with "add new person" form.

What is the link to your site?
hidden link

#2402001

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Could you give some more details about how you have this set up, so we can understand the problem?

Am I right in thinking you have a form (to submit posts), and that form includes an "Add People" dropdown for a field which stores "people" (user ids?). You also have below that an "Add new person" button.

Does that open a new form to add a person, and you expect that person to then be available in the Add people dropdown selector?

I'm struggling to see how this might work, because HTML does not permit nesting forms, maybe this second form is added later to the page and you use a modal to display it.

In which case you may be able to use JavaScript to add an option to the Add people select dropdown, but it rather depends on the setup.

Could you please give more details about how you are implementing this?

#2402099

Am I right in thinking you have a form (to submit posts), and that form includes an "Add People" dropdown for a field which stores "people" (user ids?). You also have below that an "Add new person" button.

Yes, dropdown data is populated from another post type (People post type). "Add new person" will show pop up "add new person form" to add new person use AJAX. I am expecting the new submitted data will be available on Add people dropdown selector without refreshing the page. Is that doable with Javascript?

#2402593

Thank you for confirming this.

There is no built-in hook or filter, that can be used to selectively update a selective field through AJAX. Based on this you have two options:

1. You can set the whole page to refresh when the 'add new person' form's submission is completed.

OR

2. You'll need a completely custom script that fires when the pop-up for the 'add new person' form is closed and through a custom, AJAX call gets the latest people post's list and shows them as options in the "Add people" list.

Here are some useful guides on implementing custom AJAX calls in WordPress:
hidden link
hidden link

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/