Skip Navigation

[Closed] Update the form field after an ajax call

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.

Our next available supporter will start replying to tickets in about 0.97 hours from now. Thank you for your understanding.

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 1 year, 10 months ago.

Author
Posts
#2538339

Please refer to ticket https://toolset.com/forums/topic/update-the-form-field-after-an-ajax-call/, I have an ajax call to update the field value from backend, I want to change the value to the field and display the correct date format after the ajax call and response.

#2538615

Nigel
Supporter

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

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

If this is a Types date field then the value will be stored as a timestamp (number of seconds since 1 Jan 1970).

Your ajax call triggers some PHP code on the server that returns the value.

You can either have the PHP code return a formatted value (you could use types_render_field to give the formatted value, the same as outputting the field with a types shortcode, or you could take the raw timestamp and produce the formatted string using the PHP date function).

https://toolset.com/documentation/customizing-sites-using-php/functions/
hidden link

Or your ajax request could receive the unformatted timestamp and use JavaScript to format that data as required.

hidden link

That may be the better option because if you have a Types date field in a form that includes a hidden input with the timestamp that will be stored and a visible text field that contains the formatted date string.

(You can inspect your form in the front-end with the browser dev tools to see how that works.)

The topic ‘[Closed] Update the form field after an ajax call’ is closed to new replies.