# Notification with add to calendar link

**URL:** <https://community.gravityforms.com/t/notification-with-add-to-calendar-link/16287>\
**Category:** Get Help\
**Tags:** notifications, calendar, google-calendar, add-to-calendar\
**Created:** [November 16, 2023, 9:23pm UTC](https://community.gravityforms.com/t/notification-with-add-to-calendar-link/16287 "2023-11-16T21:23:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![com3rddesign](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@com3rddesign](https://community.gravityforms.com/u/com3rddesign)\
**Post date:** [November 16, 2023, 9:23pm UTC](https://community.gravityforms.com/t/notification-with-add-to-calendar-link/16287/1 "2023-11-16T21:23:49Z")

</div>

**Hi All,**  
Is there an easy way to add a calendar link to customers’ email notifications based on a field?

The scenario of the form:

1. The user selects a date for an appointment
2. They click send, which sends back a notification and an email with a link for them to add the appointment to their calendar.

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![obijuan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/obijuan/32/13836_2.png) [@obijuan](https://community.gravityforms.com/u/obijuan)\
**Post date:** [November 16, 2023, 9:51pm UTC](https://community.gravityforms.com/t/notification-with-add-to-calendar-link/16287/2 "2023-11-16T21:51:15Z")

</div>

Hi,

You should be able to integrate your appointment form with Google Calendar with an appointment add-on.

Here are a couple of add-ons you can check with this functionality:

[https://www.gravityforms.com/add-ons/bookings-for-gravity-forms/](https://www.gravityforms.com/add-ons/bookings-for-gravity-forms/).

[https://www.gravityforms.com/add-ons/simply-schedule-appointments/](https://www.gravityforms.com/add-ons/simply-schedule-appointments/).

---

<div class="post-metadata">

**Author:** ![com3rddesign](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@com3rddesign](https://community.gravityforms.com/u/com3rddesign)\
**Post date:** [November 17, 2023, 12:58am UTC](https://community.gravityforms.com/t/notification-with-add-to-calendar-link/16287/3 "2023-11-17T00:58:19Z")

</div>

Hi Juan,  
Thank you for your reply

```
> https://www.gravityforms.com/add-ons/bookings-for-gravity-forms/.
> https://www.gravityforms.com/add-ons/simply-schedule-appointments/.

```

These add-ons seem like a more elaborate calendar functionality and it does not meet the function that I am after.

All I wanted to do was have the notifications email also have a calendar link that the user can click and add to their calendar on their computer.

Something similar to the following but also embedded in the customer notification email.

 ![Screenshot 2023-11-17 at 11.56.51 am](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/6/621bbdc378591fe885f09e0b53b8599a43f9c05e.jpeg)  
Figure: Add appointment to your calendar

---

<div class="post-metadata">

**Author:** ![obijuan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/obijuan/32/13836_2.png) [@obijuan](https://community.gravityforms.com/u/obijuan)\
**Post date:** [November 18, 2023, 1:08am UTC](https://community.gravityforms.com/t/notification-with-add-to-calendar-link/16287/4 "2023-11-18T01:08:55Z")

</div>

Hi!

There is actually a way to achieve what you have described.

To create an ‘Add to Calendar’ link for Google Calendar, you can leverage the following link structure:

`https://www.google.com/calendar/render?action=TEMPLATE&text={YOUR_EVENT_TITLE}&dates={START_DATE/END_DATE}&details={DESCRIPTION}&location={LOCATION}`

You can provide:

1. An event title.
2. A start and end date. Date and Time.
3. A description.
4. A location.

And you can build the URL in the Notification message body.

You can feed the variables in the form manually by entering the details or dynamically from the form fields.

The challenge here is with the date field. The format is mm/dd/yyyy.

Google Calendar needs a specific date format in the URL, or the ‘Add to Calendar’ won’t work.

To solve this, you need to intercept the date selected by the user in the form’s date field, store it, and pass it to the URL in the notification.

You need:

1. A hidden field.
2. A script that will process the value in the Date field and store it in the right format on the hidden field.
3. Pass the hidden field value to the URL in the Notification message body.

Once you add the hidden field, take note of the field’s ID.

Also, take note of the Date field ID.

Please see the snippet to process the date below:

```auto
add_action('gform_pre_submission', 'format_date_for_google_calendar');
function format_date_for_google_calendar($form) {
    // This is an array. This supports multiple forms, comma-separated.
    $target_form_ids = [FORM_ID]; // Replace FORM_ID with your form ID.

    // Check if the current form's ID is in the target form IDs array
    if (!in_array($form['id'], $target_form_ids)) {
        return; // Exit if it's not one of the targeted forms
    }

    foreach ($form['fields'] as &$field) {
        if ($field->type != 'date' || $field->id != DATE_FIELD_ID) continue;

        $date_value = rgpost('input_' . $field->id);

        // Determine the date format
        $date_format = strpos($date_value, '-') !== false ? 'Y-m-d' : 'm/d/Y';
        $date = DateTime::createFromFormat($date_format, $date_value);

        if ($date === false) {
            error_log('Failed to parse date: ' . $date_value);
            return;
        }

        // Format the date for Google Calendar
        $start_date = $date->format('Ymd\THis\Z');
        $date->modify('+1 hour'); //Define the meeting duration. Change to match your needs.
        $end_date = $date->format('Ymd\THis\Z');

        // Update the hidden field with the formatted date
        $_POST['input_' . HIDDEN_FIELD_ID] = $start_date . '/' . $end_date;
    }
}

```

In the code above, make sure to replace FORM\_ID, DATE\_FIELD\_ID, and HIDDEN\_FIELD\_ID.

In the Notification message body, you can reference the value of specific fields like this: {field\_id:ID\_NUMBER}.

Saying your hidden field’s ID is 5, it would be {field\_id:5}.

Then, you can create a link with the Insert Link option in the editor.

![image](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/e/e27dca8ec06e3e2cf7123fe1fd6baa7293628477.png)

Make sure to replace {START\_DATE/END\_DATE} with your {field\_id:ID\_NUMBER} in the URL, like so:

`https://www.google.com/calendar/render?action=TEMPLATE&text={YOUR_EVENT_TITLE}&dates={field_id:ID_NUMBER}&details={DESCRIPTION}&location={LOCATION}`

You can manually set the other variables or reference them dynamically from IDs in the form.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/gravityforms1/original/2X/f/fef63f0599c45e0218c30d9f5d7ca8bff9b00189.png) [@system](https://community.gravityforms.com/u/system)\
**Post date:** [December 18, 2023, 1:08am UTC](https://community.gravityforms.com/t/notification-with-add-to-calendar-link/16287/5 "2023-12-18T01:08:59Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
