Custom action in Pro Forms

Hey, I have Pro Form with numeric field which I would like to validate before user registering. For that I have an actions selected in this order - Custom, User Registration, User Meta Update, Redirect.
For the custom function I am checking the number and returning success or error message, but whatever is the result - form is always registering user. I would like to not register user if the custom action will not be success - can I somehow stop doing the next form action if custom is error? Below is my PHP function:
function my_form_custom_action( $form ) {
$fields = $form->get_fields();
$formId = $fields[‘vcsdio’];
$postId = $fields[‘postId’];
$settings = $form->get_settings();
$files = $form->get_uploaded_files();
$long = strlen($fields[‘form-field-yastbz’]);
if ($long == 7){
$n1 = $fields[‘form-field-yastbz’][0];
$n2 = $fields[‘form-field-yastbz’][1];
$n3 = $fields[‘form-field-yastbz’][2];
$n4 = $fields[‘form-field-yastbz’][3];
$n5 = $fields[‘form-field-yastbz’][4];
$n6 = $fields[‘form-field-yastbz’][5];
$n7 = $fields[‘form-field-yastbz’][6];
$result = $n21+$n32+$n43+$n54+$n65+$n76;
$mod = $result%11;
if($mod == $n1 || $fields[‘form-field-yastbz’] == 7777777){
$form->set_result([
‘action’ => ‘my_custom_action’,
‘type’ => ‘success’, // or ‘error’ or ‘info’
‘message’ => esc_html__(‘Poprawny numer PWZ, konto zarejestrowane’, ‘bricks’),
]);
} else {
$form->set_result([
‘action’ => ‘my_custom_action’,
‘type’ => ‘error’, // or ‘error’ or ‘info’
‘message’ => esc_html__(‘Niepoprawny numer PWZ’, ‘bricks’),
]);
}
} else {
$form->set_result([
‘action’ => ‘my_custom_action’,
‘type’ => ‘error’, // or ‘error’ or ‘info’
‘message’ => esc_html__(‘Niepoprawna ilość znaków numeru PWZ’.$settings, ‘bricks’),
]);
}

}
add_action( ‘bricks/form/custom_action’, ‘my_form_custom_action’, 10, 1 );

1 Like