Tag: Email

So you want to programmatically fire off a form notification email?  Here's one way to do it.  Let's be clear that I have no idea if this is the "correct" way.  I just got sick of asking this question myself and seeing other people asking it, so I figured I'd try to solve it myself. Also, you'll need to figure out a way to populate the entry id (or entire entry) as well as the action_id.  See the comments in the code.

	$entry_id = 72; // somehow you have to set the entry id of the form entry you're dealing with
	$target_action_id = 177; // id of the action you want to fire off - you can get this from the database WP_POSTS with the post_type = 'frm_form_actions'
				 //  or get it from the FF UI by opening the action and scrolling all the way down to the bottom right where it says "Action ID:

	$entry = FrmEntry::getOne($entry_id, true);
	$form_id = $entry->form_id;
	$type = "email"; // whichever you want
       	$actionToDo = FrmFormAction::get_single_action_type( $target_action_id, $type );

	$form = FrmForm::getOne($form_id);

	FrmNotification::trigger_email( $actionToDo, $entry, $form );
×Warning: This tutorial was created 2086 days ago. Some of the information may be out of date with more recent versions of Formidable. Please proceed with caution and always perform a backup before adding custom code.

The main issue with a GDPR request (when an email address is provided by the request form) is to make sure the request comes from the legitimate source. Therefore an workflow involving sending the initial confirmation to the email address provided with an unique link to be clicked if the request is legitimate should be put in place.

Using Formidable Forms I did the following:

  1. I setup a Confirmation page with a custom template. Inside the custom template I was using this piece of code: https://pastebin.com/G6NsgpNr
  2. On the form itself I added 2 hidden fields: one token field with [get_token] shortcode value. The shortcode is to be defined to return a random string such as: md5(uniqid(rand(), TRUE)); The second field holding as static value the name of a callback function to be ran when the confirmation link is clicked
  3. Define that callback function to do whatever you like to do. For instance to update another hidden field inside the form to mark the confirmation event
  4. on the email action of the form add this link: https://example.com/confirmation/?e=[id]&a=1&v=2&t=[2] where 1 is the field ID of the action field, 2 is the field id of the token field

The workflow is like this: the entry is created when a visitor submits a request. The initial email action is triggered by the create event and sends the unique link to the entry email address on the email address field. When the user clicks that link to validate the request, it opens the processing page (see pastebin code). The page checks if the token sent in the link matches the token saved withing the entry. If true then it performs the validation by calling the callback function.

The same confirmation page can resolve confirmations for any number of forms, just by updating the necessary field ids.

If anybody has a simpler, leaner solution I am interested to learn.

×Warning: This tutorial was created 2143 days ago. Some of the information may be out of date with more recent versions of Formidable. Please proceed with caution and always perform a backup before adding custom code.

Add this snippet to your functions.php file or use the Code Snippets plugin:

add_shortcode('users-email-domain',extract_domain_func);
function extract_domain_func(){
   $current_user = wp_get_current_user();
   $email = $current_user->user_email;
   if( filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
      // split on @ and return last value of array (the domain)
     $domain = array_pop(explode('@', $email));
     return $domain;
   }
}

Usage [users-email-domain]

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right