Custom Form Element submit message

I am using a custom action with the Form Element and after doing a whole lot of stuff in the custom action, I want to get a number to be displayed in place of the default success message. This is my code:

 $str_width = $fields['form-field-mbszoi']; //It's a number field

	$form->set_result([
		'action' => 'my_form',
		'type'    => 'success', //or danger or info
		'message' => esc_html__( strval($str_width), 'bricks'),
	]);
  }
  add_action( 'bricks/form/custom_action', 'my_form_custom_action', 10, 1 );

It returns the default:
Message successfully sent. We will get back to you as soon as possible.

Please help!

Hi @khan360,

To custom the form success message, you can output a PHP function using dynamic data in the Bricks Builder.

Have a great day,
Thomas

1 Like

@HomeSweetTom Thank you so much. This comes as such a surprise and makes sense to be able to have a function there :smiley:

I’ll try and get back to you asap.

But still, I wonder what’s the point of the message arg in set_result function in the AJAX call?

@HomeSweetTom Ok I tried it but it is not working for me. So in my Success Message, I have this:
{echo:outputMe}

And then in my custom action function I have this:

$fields = $form->get_fields();
$name = $fields['form-field-idpfak'];
$str_type = $fields['form-field-rchtwd'];
$str_width = $fields['form-field-mbszoi'];

$new_width =  $str_width * 1.2;

function outputMe(){
	return $new_width ;
}

The data I am trying to display, $str_width, is a number, but it doesn’t work even when a word is passed.
It just shows up a blank green container for the message. Any help would be greatly appreciated.

I have the same problem.