SEM Labs

Handcrafted Pixels, Code & Title Tags

Actions & Triggers

XFL

Triggers

Triggers are used to trigger different actions (or states) in the XFL parser. There are two triggers for the XFL parser.

Submit Trigger

The value trigger is used to set the XFL parser's action to submit. The action trigger will be most likely be from $_GET or $_POST.

The submit trigger takes precedence over the get trigger. So if both are set the parser will go into submit mode. If only the get trigger is set, the parser will go into get mode and if none are set the parser will remain in the NULL action.

In the form defined in the form creation section, we added the following line to the PHP file:

$demo->process();

To set the parser into the submit action, we need to provide a value to the first argument. For example, to set the parser into submit action using the $_POST[submit] variable, we would write:

$demo->process( $_POST['submit'] );

Get Trigger

The value trigger is used to set the XFL parser's action to get, with the purpose of allowing the controller class to populate the form.

In the form defined in the form creation section, we added the following line to the PHP file:

$demo->process();

To set the parser into the get action, we need to provide a value to the second argument. For example, to set the parser into get action using the $_GET[id] variable, we would write:

$demo->process( false, $_GET['id'] );

Actions

Actions are different processing states of the XFL parser. There are three different states: get, submit and NULL.

Get

The XFL parser's action becomes get when the get trigger is not false. The purpose of the get action is to allow the controller class to populate a form with values. For example in a content management system, you might use $_GET[id] as a trigger to load different records from a database. When the parser goes into get, the onGet event will be called if it exists.

Submit

The XFL parser's action becomes submit when the submit trigger is set. When in submit, the form will be parsed and the post values updated according to definitions in the XFL document. Once the form has been parsed the onSubmit event is called, allowing you to take further action with the posted values – such as insert them into a database.

By default the submit action is entered when either the $_GET or $_POST variable are set. This can be changed by defining a submit trigger.

NULL

The XFL parser's action remains NULL when neither the get or submit actions are triggered. Printing a form out when the action is NULL will return a blank form. This will probably be the desired result for contact forms, comment forms etc.

Events

Events are run at certain points of the XFL parser, to allow you to influence the form. There are four different events.

OnLoad

The onLoad event occurs when a form is loaded and provides the ability to carry out pre-processing modifications. For example if you wanted to populate a select element with options. To add onLoad processing, add an onLoad method to your form controller. The onLoad event occurs irrespective of the parser's mode.

onGet

The onGet event occurs when the parser goes into the get action. This allows you to supply an array to populate the form. To add onGet processing, you add an onGet method to your form controller. An array returned by the onGet method will be used to populate the form.

onSubmit

The onSubmit event occurs after the parser has processed the form and no validation errors were triggered. This allows you undertake take additional processing on the modified post array, e.g. insert its values into a database. To add onSubmit processing, add an onSubmit method to your form controller.

onComplete

The onComplete event occurs after the parser has finished all processing. To add onComplete processing, add an onComplete method to your form controller. The onComplete event occurs irrespective of the parser's mode.