Skip to content

Instantly share code, notes, and snippets.

@Crocoblock
Last active May 14, 2025 08:09
Show Gist options
  • Save Crocoblock/f3c6237e3aa5156a7e0caac9d8c26476 to your computer and use it in GitHub Desktop.
Save Crocoblock/f3c6237e3aa5156a7e0caac9d8c26476 to your computer and use it in GitHub Desktop.
JetFormBuilder Call Hook action
<?php
add_action( 'jet-form-builder/custom-action/test-hook', function( $request, $action_handler ) {
//get value of field field1
$value = $request['field1'];
//or using jet_fb_context()->resolve_request()
$value = jet_fb_context()->resolve_request()['field1'];
//return an error if field1 is less than 10
if ( isset( $request['field1'] ) && ( int ) $request['field1'] < 10 ) {
throw new \Jet_Form_Builder\Exceptions\Action_Exception( 'field1 is less than 10');
}
//set field1 value to 20
jet_fb_context()->update_request( 20, 'field1' );
//Update value inside specific row in the repeater
//Where: 0 - first row in th repeater
jet_fb_context()->update_request( 'repeater_name.0.field_name', 'new inner field value' );
// or this way
jet_fb_context()->update_request( array( 'repeater_name', 0, 'field_name' ), 'new inner field value' );
//Update specific field in each row of repeater
foreach ( jet_fb_context()->iterate_inner( 'repeater_name' ) as $context ) {
$context->update_request( 'field_name', 'new inner field value' );
}
//get ID of the post, created by "Insert/Update Post" action
$inserted_post_id = $request['inserted_post_id'];
//check what data comes to hook
//jet_fb_context()->resolve_request() to get request with the changes
//form execution will be interruppted, though you will be able to check what may be the reason of the hook not working as intended
$request_from_context = jet_fb_context()->resolve_request();
var_dump( $request, $request_from_context );exit;
}, 0, 2 );
@haseebali
Copy link

Line 17: jet_fb_context()->update_request( 20, 'field1' );

Line 21: jet_fb_context()->update_request( 'repeater_name.0.field_name', 'new inner field value' );

So, which is correct, 1st parameter is the field name and 2nd parameter is the new field value ?

Look, i have used for one of my custom functionality:

// Set the new path in JetFormBuilder dynamically
jet_fb_context()->update_request($converted_url, 'converted_video_upload');

It's working very well so the 1st parameter is "Field Value" and 2nd parameter is "Field Name".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment