SEM Labs

Handcrafted Pixels, Code & Title Tags

Modifying Forms

XFL

There are a number of scenarios in which forms need to be modified each time they are loaded. Some examples would be select elements that need to be populated with options from a database and forms that need elements adding to them depending on the parameters set. XFL allows you to modify forms before they are parsed.

Modifying forms can be undertaken by any of the four XFL events that can be added to form controller classes. It is most likely that you will want to use the onLoad method to modify forms as this is called before processing begins.

PHP DOM and XPath

Modifying XFL documents requires at least basic knowledge of the PHP DOM API and XPath. XPath allows you to query the XFL document and PHP DOM allows you to add, edit and remove nodes. The XFL parser utilises an XML class, which provides shortcuts to PHP DOM functionality.

Example

Using the same XFL document from the form creation section, below we will edit the form to include a select box with options and a new text input element and validator. Note: this example is using shortcuts from the XML class.

Now when you return the form you should see the new select and input element. See the XML class documentation for more information on using PHP DOM to manipulate XFL documents.