• Resolved squaredot

    (@squaredot)


    Would it be possible to use the “all fields” merge tag but exclude certain form data out of that tag?

    For example, {all_fields}+{exclude terms_conditions}… Or something along those lines.

    That way, you could add all fields and exclude some, which would be much much easier than having to add each merge tag individually and leave out the ones you don’t want for email notifications after form submit.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @squaredot,

    Trust you are doing good and thank you for reaching out to us.

    Unfortunately, it’s not possible to exclude a couple of fields alone from the {all_fields} macro. However, I have pinged our developers to check if a workaround could be suggested regarding this. We’ll update you here once we have more feedback on this as soon as possible.

    Kind Regards,
    Nebu John

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @squaredot,

    Our developers worked on a custom solution for this, could you please test the same in your staging or development environment?

    <?php
    
    add_action( 'forminator_form_before_save_entry', function( $module_id ) {
    	$form_id = 6; // Replace this with the target form ID.
    	$fields  = array( 'name-1', 'email-1' ); // Field slugs.
    	if ( $form_id !== (int) $module_id ) {
    		return; // Not the target form.
    	}
    	add_filter( 'forminator_custom_form_before_form_fields', function( $all_fields, $custom_form, $data ) use ( $fields ) {
    		$custom_fields = array();
    		foreach( $all_fields as $f ) {
    			if ( in_array( $f->slug, $fields ) ) {
    				$custom_fields[] = $f;
    			}
    		}
    		return $custom_fields;
    	}, 10, 3 );
    });

    Substitute the $form_id variable with your form ID and the $fields variable with an array containing the field slugs you wish to include in the notification email. Any other elements will be excluded from the {all_fields} macro.

    The code could be added using a mu-plugin. I hope the following guide comes in handy: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Kind Regards,
    Nebu John

    Thread Starter squaredot

    (@squaredot)

    Thank you Nebu.
    This does work in the way that it ONLY includes fields that are not in the array. My goal was to include all fields but remove SOME of them. So the simple change to the custom solution is the following:

    if ( in_array( $f->slug,...)

    Becomes:

    if ( !in_array( $f->slug,...)

    That way, any fields that are not in the array will be displayed in the notification.

    Thank you all very much for creating this solution!

    • This reply was modified 1 year, 3 months ago by squaredot.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom merge tag capability for email notification’ is closed to new replies.