Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuadavidnelson/d7249dab0b1520d7c362 to your computer and use it in GitHub Desktop.
Save joshuadavidnelson/d7249dab0b1520d7c362 to your computer and use it in GitHub Desktop.
Perhaps this is what you're trying to do...
<?php
/**
* Example code for comment #11224.
*
* @link http://joshuadnelson.com/user-dropdown-list-custom-notification-routing-gravity-forms/#comment-11224
* @author Joshua David Nelson, josh@joshuadnelson.com
*/
// Route to user address from drop down list, update the '1' in the filter name to the ID of your form
// For example, 'gform_notification_2' would be for form id '2'.
add_filter( 'gform_notification_1', 'route_user_email_notification', 10, 3 );
function route_user_email_notification( $notification, $form , $entry ) {
foreach( $form['fields'] as &$field ) {
// Similar to above, find the right field. If it's not the right one, move onto the next field
if( $field['type'] != 'select' || strpos($field['cssClass'], 'studio-list') === false )
continue;
// Pull out the POST id selected, by the field id from the $entry
$field_id = (string) $field['id'];
$post_id = $entry[ $field_id ];
}
// Set the email address to send the email to
// In this case you're using a post id to grab a post meta value
if( !empty( $post_id ) ) {
$email_to = get_post_meta($post_id, 'studio_email_1', true);
}
// Note that if the get_post_meta returns nothing, this won't work. Be sure there is a value set!
if ( !empty( $email_to ) && is_email( $email_to ) ) {
$notification[ 'to' ] = $email_to;
}
return $notification;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment