Using frmapi_post_response will not update field in form

By: Doug Casebolt | Asked: 07/08/2024
ForumsCategory: Code SnippetsUsing frmapi_post_response will not update field in form
Doug Casebolt asked 6 months ago

Hello,   I am using the "Send API Data" action on one of my forms to generate a QR code from a provider.  The action works as it creates the QR code on the providers system for me to view.  The API in question returns a URL for the location of the QR Code.  I am using the following snippet to write that data back to a text field for the submitted form: 


add_action( 'frmapi_post_response', 'frm_save_api_response', 10, 3 );
function frm_save_api_response( $response, $entry, $form_action ) {
$body = json_decode($response["body"], true);
$returned_id = $body["png"]; // this line will change based on the API you are sending to
if ( $returned_id ) {
FrmProEntryMeta::update_single_field( array(
'entry_id' => $entry->id,
'field_id' => 103, // change to the ID of the field to change
'value' => $returned_id,
) );
}
}

Per the directions found on https://formidableforms.com/knowledgebase/formidable-hooks/ I have set the snippet to PHP and made it active.


I have logging enabled and it shows the API functioned properly and the response has the key/vale pair I am calling out.

Likewise I have added the snippet:
add_action( 'frmapi_post_response', 'frm_get_api_response', 10, 3 ); function frm_get_api_response( $response, $entry, $form_action ) { $status = wp_remote_retrieve_response_code( $response ); if ( $status == 200 ) { add_filter('frm_main_feedback', 'frm_add_200_to_message' ); } else { add_filter('frm_main_feedback', 'frm_add_500_to_message' ); } } function frm_add_200_to_message( $message ) { $message .= ' The API call was successful'; return $message; } function frm_add_500_to_message( $message ) { $message .= ' The API call was not successful'; return $message; }

and ran a submission of the form and received a "The API call was successful" response on the confirmation screen.

My issue as the subject line suggests is that it fails to update the field. I have also put in a default value as the directions at https://formidableforms.com/knowledgebase/frm_api_post_response/ suggest.
2 Answers
Rob LeVineRob LeVine answered 6 months ago
I suggest using some form of debugging to output the result returned from FrmProEntryMeta::update_single_field
Doug Casebolt answered 5 months ago
I was able to figure it out, the permissions on the snippet were not correct.  Thank you for your help.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right