Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // updated version of http://pastebin.com/Rws5p0T5 for gmuhr
- // http://www.gravityhelp.com/forums/topic/dynamic-population-notification-strategy
- // NOTE - change here to apply to all forms; drop the _1
- add_filter('gform_notification_email', 'populate_admin_email_via_db', 10, 2);
- function populate_admin_email_via_db($email,$lead) {
- // setup the array mapping the form ID to the field where the accountID will be available
- // format: form ID => field ID
- $idField = array (
- 1 => 28,
- 8 => 55,
- 3 => 29,
- 7 => 60,
- 11 => 73,
- 5 => 68,
- 4 => 33,
- 9 => 74,
- 13 => 98,
- 14 => 103);
- // if the form_id in the entry is NOT in the array of forms we want to process
- // just return the email address
- if (!array_key_exists($lead['form_id'], $idField)) {
- return $email;
- }
- // set the email we're going to return equal to the email that was passed
- // in from the admin settings, in case something fails
- $selected_email = $email;
- // database connection details
- $dbname = 'xxxxx';
- $dbuser = 'xxxxx';
- $dbpass = 'xxxxx';
- $dbhost = 'localhost';
- $dbtable = 'xxxxx';
- // changed this line to use the form ID and field ID from the idField array
- // continue: if the form_id is in our array, then grab the accountID and pull the email address
- $account = $lead[$idField[$lead['form_id']]];
- // establish the connection
- $link = mysql_connect($dbhost, $dbuser, $dbpass);
- // if connection was established
- if ($link){
- $sql = "SELECT email FROM $dbname.$dbtable WHERE activation_key='$account' LIMIT 1;";
- $result = mysql_query($sql);
- // deal with the results
- if($result) {
- // the email address will be the one and only record returned
- $returned_record = mysql_fetch_row($result);
- if(!empty($returned_record))
- $selected_email = $returned_record[0];
- }
- // close the connection if it was established
- mysql_close($link);
- }
- // return an email address one way or the other
- return $selected_email;
- }
Advertisement
Add Comment
Please, Sign In to add comment