Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.