2

After someone fills out a form on my site (using gravity forms) is there any known integration/widget that would allow me to have an "Add this event to my Outlook Calendar" link in the submission email/text?

Thanks

1 Answer 1

3

I am not aware of any special plugin to do that , there are many that have this functionality , but only when using as a whole event system (and not specific to gravity forms as far as i know). But - fortunately , it is fairly easy to make with PHP : you just have to construct a simple string.

header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=event.ics");
$ics_string = 'BEGIN:VCALENDAR\n';
$ics_string .= 'VERSION:2.0\n';
$ics_string .= 'PRODID:-//whatever//NONSGML //EN\n';
$ics_string .= 'METHOD:REQUEST\n'; // requied only 4  Outlook
$ics_string .= 'BEGIN:VEVENT\n';
$ics_string .= 'UID:'.date('Ymd').'T'.date('His').'-'.md5(uniqid(mt_rand(), true)).'-mystrinng'; // requied only 4  Outlook - you can use only simple rand(0,999999)
$ics_string .= 'DTSTAMP:".date('Ymd').'T'.date('His')."\n'; //requied only 4  Outlook
$ics_string .= 'DTSTART:20120416T000000\n'; // april 16 2012, T = HHMMSS
$ics_string .= 'SUMMARY:your summery\n';
$ics_string .= 'DESCRIPTION: your description\n';
$ics_string .= 'END:VEVENT\n';
$ics_string .= 'END:VCALENDAR\n';
echo $ics_string;

of course , you will populate the fields with whatever you want , for example :

$summery = get_the_title();
$desc = get_the_excerpt();

and in the string :

 $ics_string .= 'SUMMARY:' . $summery . '\n';

or

 $ics_string .= 'DESCRIPTION:' . $desc . '\n';

you can even use GET or POST

echo 'DTSTART:$_GET[date]\n';
echo 'SUMMARY:Go to a movie with ' . $_GET[girlfriend] . '\n';
echo 'DESCRIPTION: be careful not to be caught by ' . $_GET[other_girlfriend] . ' or ' .$_GET[wife] .'\n';

see specs for format here : http://www.kanzaki.com/docs/ical/

here http://www.ietf.org/rfc/rfc2445.txt

or here http://en.wikipedia.org/wiki/ICalendar

5
  • Thanks! So if i were to plug this in now, would the default field titles in Gravity Form apply?
    – daniel
    Feb 22, 2012 at 17:17
  • well - it should work with any form submission, or with any other available function/variable .. I am sorry i can not say more - I have never used gravity forms and am not so familiar with it´s API. Someone else might help on this specific plugin. I know they have quit a bit of hooks. one that you might want to activate this whole ical function is gform_post_submission();
    – krembo99
    Feb 22, 2012 at 17:28
  • Great. Thanks for the info. So if I put all the info in functions.php will anything actually have to be in the submission text area? If I'm reading this all right (and hopefully i am!) if i have "event.ics" with variables set for the date/time, when i provide the link to "add to calendar" i can just point "event.ics" each time and the right information will be there? Thanks so much for this help -- you're a lifesaver!
    – daniel
    Feb 22, 2012 at 17:35
  • +1 for the details, the solution, the explanation. But +10 for echo 'DESCRIPTION: be careful not to be caught by ' . $_GET[other_girlfriend] . ' or ' .$_GET[wife] .'\n'; :D
    – kaiser
    Feb 22, 2012 at 19:42
  • Escape your variables before you print them out. $_GET[other_girlfriend] may contain malicious code. ;)
    – fuxia
    Feb 22, 2012 at 19:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.