Hello,
I’m back. Yes absolutely, there’s multiple ways to do actions or send e-mails, based on the user input.
If you have an “E-mail” action in your form, and let’s say you want to change the recipient based on a field in your form. You can add the following code in your theme functions.php
:
add_filter('acfe/form/submit/email/args/name=my-form', 'my_form_email_action', 10, 3);
function my_form_email_action($args, $form, $action){
/**
* @array $args The email arguments
* @array $form The form settings
* @string $action The action alias name
*/
/**
* $args = array(
* 'from' => '[email protected]',
* 'to' => '[email protected]',
* 'subject' => 'Subject',
* 'content' => 'Mail content',
* 'headers' => array('From: [email protected]', 'Content-Type: text/html', 'charset=UTF-8'),
* 'attachments' => array(),
* );
*/
/**
* Get the value from the form input named 'my_field'
* This is the value entered by the user during the form submission
*/
$my_field = get_field('my_field');
if($my_field === 'my_choice'){
$args['to'] = '[email protected]';
}
return $args;
}
If you want to send an additional and a different e-mail, based on the user input, you can add an another e-mail action, and the use the same filter.
Note: If you return $args = false;
in this filter, the email won’t be sent, so you can play with that return depending on your logic.
You can also add a custom action, and write your own wp_mail()
inside the hook action('acfe/form/submit/my-custom-action', $form, $current_post_id)
. You can still use get_field('my_field')
inside it, to retrieve the input set by user in the form ??
Hope it helps!
Note: I’ll add this e-mail hook as an example in the E-mail action.
Regards.