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.
Please login or Register to submit your answer