Score:0

Is there a way for a Webform submission to include a value returned from an Ajax callback prior to the form being submitted?

cn flag

I have a custom composite webform element that is made up of a textfield, a button, and a markup element to show a response.

The user enters a value in the textbox, clicks the button, and an Ajax callback sends a request to an external API which then shows the reponse below the textfield. This is done prior to the user submitting the form.

When the user submits the form, the value entered into the textfield is included in the submission but the response from the Ajax callback in the markup element is not.

Is there a way for the webform submission to include the value returned from the Ajax callback in the markup element?

id flag
You have an existing form alter implementation using AJAX API and you are asking how to modify it. Do I have that right?
thiokol avatar
cn flag
@cilefen I have the Ajax callback working ok, it returns the data and displays it as required in the markup element before the form is submitted, but after the form is submitted the submission does not contain that markup element with the data returned from the API, I think this is because I am only returning the data via Ajax and displaying it on the form, but not storing that data into the form state prior to the form being submitted?
id flag
I suppose if we saw your code we could perhaps offer an answer.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.