Support

Account

Home Forums General Issues Using ACF Email Field for Gravity Forms Notifications

Solved

Using ACF Email Field for Gravity Forms Notifications

  • I am working on a contact form which is connected to the staff directory page. The staff directory page passes post_id to the contact form page, and I am able to use this to pull values from the corresponding ACF entry.

    The problem I am trying to address is making sure the Staff Member’s email address is not revealed – even in the source code.

    Currently I have the form set so the staff_email field is set to administrative. Unfortunately this still allows the email address to be seen in the source code. Any bot running a regular expression will pick it up in no time. The obvious reason for this is to protect against the email address being scraped by a spammer’s bot.

    What I would like to do is have the form fetch the staff_email ACF field after the form is submitted and populate the email address in the notification To address.

    I have tried the two functions below, and neither of them work.

    First Attempt

    add_filter( 'gform_notification_55', 'acf_email', 10, 3);
    function acf_email ($notification, $form, $entry){
    $post_id = rgar($entry, '14');
    $notification['to'] = get_field('staff_email', $post_id);
    return $notificaiton;
    }

    Second Attempt

    add_filter( 'gform_notification_55', 'acf_email', 10, 3);
    function acf_email ($notification, $form, $entry){
    if ($notification['name'] == "Web Contact"){
    $notification['toType'] = 'routing';
    $notificaiton['routing'] = array(
    'fieldID' => 1,
    'operator' => 'is',
    'value' => get_field('full_name', get_post_id()),
    'email' => get_field('staff_email', get_post_id())
    );
    return $notificaiton;
    }

  • For this filter:

    add_filter( 'gform_notification_55', 'acf_email', 10, 3);
    function acf_email ($notification, $form, $entry){
      $post_id = rgar($entry, '14');
      $notification['to'] = get_field('staff_email', $post_id);
      return $notification;
    }

    Notification was misspelled in the returning line (‘notificaiton’). There is also a misspelling of it in two places on the second filter tried, but I think that one has other problems, as well.

    Beyond making sure there is no typo in notification throughout any given filter used, I’d verify:
    1) 55 is the correct form ID of the form you’re trying to modify this on
    2) 14 is the correct ID of the field that the post ID you’re passing to this form is located inside of.

  • I blame my lazy fingers for the transposition in notification.

    After some minor modifications – and fixing typos, I got this working using my second example above:

    add_filter( 'gform_notification_55', 'acf_email', 10, 3);
    function acf_email ($notification, $form, $entry){
    	$post_id = rgar($entry, '14');
        GFCommon::log_debug( __METHOD__ . '(): Running for Form 55.' );
        GFCommon::log_debug( __METHOD__ . '(): The Entry => ' . print_r( $entry, true ) );
        GFCommon::log_debug( __METHOD__ . '(): The Notification => ' . print_r( $notification, true ) );
    	if ($notification['name'] == "Web Contact"){
    		$notification['to'] = get_field('staff_email', $post_id);
    		$notification['toType'] = 'routing';
    		$notification['routing'] = array(
    			'fieldID' => 1,
    			'operator' => 'is',
    			'value' => get_field('full_name', $post_id),
    			'email' => get_field('staff_email', $post_id)
    		);
    	GFCommon::log_debug( __METHOD__ . '(): Email To => ' . print_r( $email_to, true ) );
    	GFCommon::log_debug( __METHOD__ . '(): Modified Notification => ' . print_r( $notification, true ) );
    	return $notification;
    	}
    }
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.