WIP: Automatically Trigger Form Custom Action Hook

Hey,

Just wondering if it would be possible to automatically trigger the custom action hook instead of having to select it as an action in each form.

I’m thinking about if someone were to build a plugin to save form submissions in the wordpress database, they’d have to have the user select the custom action on every form to make sure that they get saved.

Not the end of the world. Just a thought I had.

I had thought that maybe I could force it to be selected with the new settings filter in 1.5, but it doesn’t seem to care if I modify the actions array:

add_filter( 'bricks/element/settings', function( $settings, $element ) {
	if ( $element->name === 'form') {
		if (!isset($settings['actions'])) {
			$settings['actions'] = ['custom'];
		} else if (!in_array('custom',$settings['actions'])) {
			array_push($settings['actions'],'custom');
		}
	}

    return $settings;
}, 10, 2 );

Hey @luistinygod or @timmse,

I was just hoping for some input on this topic when you have a moment.

Hello @cmstew

Thank you for your post.

The code used in your post doesn’t work because the “bricks/element/settings” hook runs on the form element render moment, and the form actions are used when the form is submitted.

But yes, your suggestion makes sense. I’ll discuss it with the team.

Thank you!
Luis