--------------------------------
Title
--------------------------------
Symphony Events
--------------------------------
Description
--------------------------------
Events are PHP classes or functions that can be attached to a page template to perform specific functions that are out of the realm of what XSLT alone can accomplish. Extensions can sometimes include events that can be attached to a page. Built into Symphony is a way of creating events that can be used to save data to the database from front-end forms as a single entry or even multiple entries at one time, with the option of sending an email message on successfully saving an entry or entries.
--------------------------------
Body
--------------------------------
PHP code cannot be inserted into XSLT, since it is not valid XML. Plus, it might compromise the security of the site if it were possible. Symphony events have been created as a way of enabling pages to take advantage of the PHP classes available in the Symphony core, or to extend these core classes with additional functionality. Continuing on with the tutorial for [Importing XML in Symphony](http://www.designprojectx.com/tutorials/importing-xml-in-symphony/), I will be creating an event to save entries by importing data from an external XML file.
#### Create an Event
The easiest way to create an event is to use the Events Editor by navigating to Blueprints : Components and clicking on the “Create New” button beside “Events”. Use the following preferences to create a new event:
##### Essentials
* Name: **Save Entry**
* Source: **Entries**
* Filter Rules: **Admin Only**
##### Description
Once saved, a PHP file will be saved to the events directory in the workspace. Also, a Description will provide instructions for using the event with a front-end form. Here’s the Description for my new “Save Entry” event:
###### Success and Failure XML Examples
When saved successfully, the following XML will be returned:
Entry [created | edited] successfully.
When an error occurs during saving, due to either missing or invalid fields, the following XML will be returned (Notice that it is possible to get mixtures of success and failure messages when using the “Allow Multiple” option):
Entry encountered errors when saving.Entry [created | edited] successfully.
...
The following is an example of what is returned if any filters fail:
Entry encountered errors when saving.Recipient username was invalid
...
###### Example Front-end Form Markup
This is an example of the form markup you can use on your frontend:
To edit an existing entry, include the entry ID value of the entry in the form. This is best as a hidden field like so:
To redirect to a different location upon a successful save, include the redirect location in the form. This is best as a hidden field like so, where the value is the URL to redirect to:
#### Allow Multiple Entries
By clicking on the “Allow Multiple” option under Filter Rules when creating an event, it is possible to save several entries at once.
##### Essentials
* Name: **Save Entries**
* Source: **Entries**
* Filter Rules: **Admin Only, Allow Multiple**
##### Description
The front-end form markup will change to allow the mapping of data to a POST array:
###### Example Front-end Form Markup
This is an example of the form markup you can use on your frontend:
Using the Save Entry event, we can now go ahead and create a front-end form that populates the field values from the XML file produced by a WordPress Export File to [Import Entries from WordPress](http://designprojectx.com/tutorials/importing-entries-from-wordpress/) into Symphony.
--------------------------------
Date
--------------------------------
25 May 2009 12:26pm
--------------------------------
Section
--------------------------------
Tutorials
--------------------------------
Category
--------------------------------
Technology
--------------------------------
Tags
--------------------------------
symphony cms, xslt