I was trying to find a way to add some custom data to the response object sent back from a Bricks custom form function.
After digging through the bricks core code I stumbled across the following hook:
// NOTE: Undocumented
$response = apply_filters( 'bricks/form/response', $response, $this );
The comments also mention this is Undocumented, hence why this may not be shown anywhere but this filter hook can be used to modify the response object before its passed back to the front end.
I added this code:
add_filter( 'bricks/form/response', 'lb_custom_form_response', 10, 2 );
function lb_custom_form_response( $response, $form ) {
//$form_fields = $form->get_fields();
//$form_id = $form_fields['formId'];
//$results = $form->get_results();
// Logic here - -example to add a single extra item to the response object
// Check if the result is a success
if( isset( $results['success']) ) {
// Loop over the success aray or you could use reset function
foreach( $results['success'] as $result) {
if ( $result['action'] === 'my_custom_action' ) {
$response['some_data'] = $result['some_data'];
break;
}
}
}
// Make sure you return a response!
return $response;
}
This will add ‘some_data’ to the json object sent back from the AJAX form submission.
Hope this helps