Can anybody see what is wrong with my code?
I am trying to create a calendar event for every event that is in the $_POST. There should be one calendar for download with several events on it.
So far it will generate a calendar file for download with the last event in the list only. It writes over the old ones.
Thanks in advance for any help.
//Set the headers
header("Content-Type: text/Calendar");
header("Content-Disposition: inline; filename=calendar.ics");
//Loop through $_POST to get all entries
foreach ($_POST['listItem'] as $value){
$dave = trim($value);
echo "BEGIN:VCALENDAR\n";
echo "VERSION:2.0\n";
echo "PRODID:www.testMeiCalendar.net\n";
echo "METHOD:REQUEST\n"; // requied by Outlook
echo "BEGIN:VEVENT\n";
echo "DTSTART:".$dave."T230000\n";
echo "DTEND:".$dave."T010000\n";
echo "SUMMARY:This is beautiful\n";
echo "LOCATION:Downtown\n";
echo "DESCRIPTION:Let's get together for New Years Eve\n";
echo "UID:ABCD1234\n";
echo "SEQUENCE:0\n";
echo "DTSTAMP:20101125T112600\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR\n";
}
Without knowing the structure of the $_POST sent to your script I’d say that there is only a single value in listItem and so that’s why it does not give output for everything. Have you debugged it to tell if it is only outputting a single value or if it’s actually outputting everything and overwriting?
__
The answer at How to get multiple parameters with same name from a URL in PHP from benlumley suggests appending [] to the end of the variable name for GET requests.
EDIT: I think the answer may be as simple as: