Dealing with XForms

» XForms defines a variation on traditionalwebforms which allows them to be used on a wider variety of platforms and browsers or even non-traditional media such as PDF documents.

The first key difference in XForms is how the form is sent to the client.» XForms for HTML Authorscontains a detailed description of how to create XForms, for the purposeof this tutorial we'll only be looking at a simple example.

Example #1 A simple XForms search form

<h:html xmlns:h=""xmlns=""><h:head><h:title>Search</h:title><model><submission action=""method="post" id="s"/></model></h:head><h:body><h:p><input ref="q"><label>Find</label></input><submit submission="s"><label>Go</label></submit></h:p></h:body></h:html>

The above form displays a text input box (named q),and a submit button. When the submit button is clicked, the form will besent to the page referred to by action.

Here's where it starts to look different from your web application's pointof view. In a normal HTML form, the data would be sent as application/x-www-form-urlencoded, in the XForms worldhowever, this information is sent as XML formatted data.

If you're choosing to work with XForms then you probably want that data asXML, in that case, look in $HTTP_RAW_POST_DATA whereyou'll find the XML document generated by the browser which you can passinto your favorite XSLT engine or document parser.

If you're not interested in formatting and just want your data to be loadedinto the traditional $_POST variable, you can instructthe client browser to send it as application/x-www-form-urlencodedby changing the method attribute tourlencoded-post.

Example #2 Using an XForm to populate $_POST

<h:html xmlns:h=""xmlns=""><h:head><h:title>Search</h:title><model><submission action=""method="urlencoded-post" id="s"/></model></h:head><h:body><h:p><input ref="q"><label>Find</label></input><submit submission="s"><label>Go</label></submit></h:p></h:body></h:html>

Note: As of this writing, many browsers do not support XForms.Check your browser version if the above examples fails.

add a note add a note

User Contributed Notes 3 notes

lphuberdeau at phpquebec dot org
13 years ago
Since HTTP_RAW_POST_DATA requires a configuration to be generated and is not enabled as a default value, you will probably have to use the PHP STDIN stream to get the raw data. It's probably better to use this method as the raw data will not be generated every time, even when not needed.

=fopen( "php://stdin", "r" );
$data ='';
while( !
feof( $fp ) )
$data .=fgets( $fp );
fclose( $fp );
12 years ago
FireFox has an XForms plugin that works with the latest nightly builds. Check out for more info. For IE support, there's an ActiveX control from Novell ( and one from (

There's also a JavaScript-based one coming out called FormFaces which looks very promising, especially since there are no plugins required and it works in IE, FF, and Opera:
Darkener Daemon EX
12 years ago
"php://stdin" doesn't exist in my PHP version. I use the following code block instead :
if (!isset($HTTP_RAW_POST_DATA))
$HTTP_RAW_POST_DATA =file_get_contents("php://input");
To Top