PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Email Based on Day

  1. Hi there,

    First off, as many have said but deserves to be said again, thanks for the great plugin. You guys have built a fantastic product.

    Now, on to the question:

    We have a client - http://curelounge.com, a nightclub - who recently had their older forms converted to Gravity Forms minus one key element: based on a date selected, a specific person gets emailed.

    So, originally, after a user chooses their reservation date, that date gets broken down to its day form and then, using switch logic, sends an email to monday@curelounge.com, tuesday@curelounge.com etc.

    I believe that all I need to do is use gform_post_submission to get the date fields (we're using the manual Date field, not the jQuery selector) and then put it through the same logic as before...but, unfortunately our developer is on vacation and I'm not sure what I need to call.

    As with any request in this field, the solution is due yesterday so any help would be much appreciated.

    Thanks so much!
    Jeremy

    Posted 13 years ago on Monday February 28, 2011 | Permalink
  2. Do you wan't to do this based on a Date field? Is it possible for you to use a Dropdown field for the dates instead? If so there is Routing functionality on the Admin Notification that lets you send to specific email addresses based on select fields (Drop down, radio button checkbox).

    If you have to use a Date field what you would use is the gform_notification_email hook to write custom code that sets the Admin Notification Send To email address.

    Here is an example of the gform_notification_email hook in use to set the Send To address:

    <?php
    add_filter("gform_notification_email", "change_notification_email", 10, 2);
    function change_notification_email($email, $form){
       return "test@test.com";
    }
    ?>

    You would want to do something similar, only you would get the value of the Date field and then use code to determine what day of the week it is and then do a switch on the day of the week to return the email address based on the day of the week.

    Let me know if you need additional information or if this is enough for you to go on.

    Posted 13 years ago on Monday February 28, 2011 | Permalink
  3. We could definitely do drop downs, but we still need to send the email based on the date selected. For example, if a person chose to reserve space on 02/28/2011, it'd send out to monday@curelounge.com. I'm pretty sure I remember reading that this isn't possible with the current routing capabilities...

    So, for gform_notification_email, I can call those three fields from the database and then add in the switch statement? Do you have an example of querying a field? If not, I'll try and get in touch with our developer to see if he has any insight but unfortunately this is just a wee-bit above my capabilities.

    Thanks again!

    Posted 13 years ago on Monday February 28, 2011 | Permalink
  4. By the way, this is how we were originally selecting the day:

    $eventday = strtolower( date( 'l', mktime( 0, 0, 0, $month, $day, $year ) ) );

    switch ( $eventday )
    {
    case 'sunday': $mailto = 'sunday@curelounge.com'; break;
    case 'monday': $mailto = 'monday@curelounge.com'; break;
    case 'tuesday': $mailto = 'tuesday@curelounge.com'; break;
    case 'wednesday': $mailto = 'wednesday@curelounge.com'; break;
    case 'thursday': $mailto = 'thursday@curelounge.com'; break;
    case 'friday': $mailto = 'friday@curelounge.com'; break;
    case 'saturday': $mailto = 'saturday@curelounge.com'; break;
    }

    Posted 13 years ago on Monday February 28, 2011 | Permalink
  5. Hi Transmyt,

    Give this a shot. Paste the following code in your theme's functions.php file: http://pastie.org/1617746

    Be sure to update the "3" on this line:

    $date_field = 3;

    ...to the ID of your date field.

    Posted 13 years ago on Monday February 28, 2011 | Permalink
  6. Hey David,

    Thanks so much, this is working almost perfectly. The emails are coming through just like they should but I'm getting the following error after submitting:

    ----------------------------------------------------------------------------------------------------------------
    Warning: strtotime() expects parameter 1 to be string, array given in /home/pbmaster/public_html/wp-content/themes/cure-lounge/functions.php on line 19.
    ----------------------------------------------------------------------------------------------------------------

    Anything I can do to resolve that?

    Thanks again, this is exactly what I was looking for.

    Posted 13 years ago on Monday February 28, 2011 | Permalink
  7. Oops, missed that part about you using the manual date field. Here is some updated code: http://pastie.org/1618206

    Also, I forgot to mention that you'll want to update the "41" following the filter name to the ID of your form so this only fires for that form.

    Posted 13 years ago on Monday February 28, 2011 | Permalink
  8. Perfect! Thank you so, so much.

    Posted 13 years ago on Monday February 28, 2011 | Permalink

This topic has been resolved and has been closed to new replies.