Bricksbuilder: forms – custom form actions

CoderAuthor Position

This is a static text. Maybe you want to add a tagline or short message here?

Bricksbuilder Forms
Bricksbuilder Forms

In this post I will collect everything that concerns Bricksbuilder: forms

Bricksbuilder – forms – custom form actions is a powerful tool that allows you to customize and enhance the functionality of your forms. With Bricksbuilder, you can create unique, interactive forms that engage your users and drive conversions.

//Custom Form Actions
function my_form_custom_action( $form ) {
// $fields = $form->get_fields();
// $formId = $fields['formId'];
// $postId = $fields['postId'];
// $settings = $form->get_settings();
// $files = $form->get_uploaded_files();

// Perform some logic here…

//acess to checkbox
if ($form->get_field_value( 'jrhkhr' )[0] == 'Так') {$adon = ' And For each question add H3 html tag';}</pre>

// Set result in case it fails</span></div>

$form->set_result([
'action' => 'my_custom_action',
'type' => 'success', //or danger or info
'message' => esc_html__('Oh my custom action failed', 'bricks'),
]);
}
add_action( 'bricks/form/custom_action', 'my_form_custom_action', 10, 1 );

Well, it might not be the most elegant solution but you could add a hidden field to your forms called custom-action, or whatever you want, and then you can define which custom action you want to trigger on that form by assigning the value. Then in your function, you could check the fields first before doing your action:

function my_form_custom_action( $form ) {
$settings = $form->get_settings();

foreach ($settings['fields'] as $field) {
if (isset($field['label']) && $field['label'] == 'custom-action') {
if ( $field['value'] == 'action-1') {
// Perform some logic here…
}
if ( $field['value'] == 'action-2') {
// Perform some other logic here…
}
}
}
}
add_action( 'bricks/form/custom_action', 'my_form_custom_action', 10, 1 );

 

More info: https://academy.bricksbuilder.io/article/form-element/