The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group

Slack Signup
Newsletter Optin
Help Desk

get some data via API and write this to a form field

Labels

This Discussion is public

Notifications

Hi, i have a contact form. if someone fill out and send the form, the data will create a customer account in my invoice software via API.

Now, i will get the (by the invoice software created) customer id via API and update the contact form entry (write this id to the field "customer_id").

With Formidable logs, i can see that i receive all relevant information via API, but how can i write now the received id to the formidable form field?

Any ideas?

Regards Peer

This sounds like a timing issue. I solved a similar problem for a client that needed to retrieve a document identifier from a remote system. The original developer created an asynchronous Ajax call that he invoked when a user clicked the submit button. The Ajax call executed every time, but the retrieved data was never stored with the form. This happened because by the time the Ajax call completed and returned the data, the form was already written to the database. What I had to do was prevent the default action of the submit button from firing. I ran the Ajax in synchronous mode to assure the submit action wouldn't take place until after the data was received and stored in a hidden field on the form. Once I confirmed the data was stored, I fired the submit() action programmatically.

Here are some diagnostic questions that may help you get to the answer:

When is the API call being fired, before clicking submit or after? Is the API call using Ajax or Rest? Does the invoice software receive and store the entry ID assigned to the saved form? If so, you should be able to link the customer ID back to the entry after the form is written to the database. If not, you really have no choice but to work out a similar solution to the one described above. Gook luck in figuring it out.

Hi, i can output the response with the following php hook, but how can i extract the id from the Array response?

add_action( 'frmapi_post_response', 'frm_get_api_response', 10, 3 );
function frm_get_api_response( $response, $entry, $form_action ) {

print_r ($response);

}

I don't have the Formidable API add-on operational in my local environment, but I did trace through the source code and from what I can see, the $response array doesn't have the ID. It would appear that the $entry object may have the ID though. You access an object's member as $entry->id, if it's in the object.

I suggest you install the Kint debugger. https://wordpress.org/plugins/kint-php-debugger/

Using Kint, you can give yourself a nice visual output of arrays, objects, or whatever.

Hey I have solved it with the debugger. Thanks for this information

Discussion closed.