Source of: /manual/en/features.xforms.php
<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/features.inc";
$setup = array (
'home' =>
array (
0 => 'index.php',
1 => 'PHP Manual',
),
'head' =>
array (
0 => 'UTF-8',
1 => 'en',
),
'this' =>
array (
0 => 'features.xforms.php',
1 => 'Dealing with XForms',
),
'up' =>
array (
0 => 'features.php',
1 => 'Features',
),
'prev' =>
array (
0 => 'features.sessions.php',
1 => 'Sessions',
),
'next' =>
array (
0 => 'features.file-upload.php',
1 => 'Handling file uploads',
),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);
manual_header();
?>
<div>
<h1>Dealing with XForms</h1>
<p class="para">
<a href="http://www.w3.org/MarkUp/Forms/" class="link external">» XForms</a> defines a variation on traditional
webforms which allows them to be used on a wider variety of platforms and
browsers or even non-traditional media such as PDF documents.
</p>
<p class="para">
The first key difference in XForms is how the form is sent to the client.
<a href="http://www.w3.org/MarkUp/Forms/2003/xforms-for-html-authors.html" class="link external">» <i>XForms for HTML Authors</i></a>
contains a detailed description of how to create XForms, for the purpose
of this tutorial we'll only be looking at a simple example.
</p>
<div class="example">
<p><b>Example #1 A simple XForms search form</b></p>
<div class="example-contents programlisting">
<div class="htmlcode"><pre class="htmlcode"><h:html xmlns:h="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/2002/xforms">
<h:head>
<h:title>Search</h:title>
<model>
<submission action="http://example.com/search"
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></pre>
</div>
</div>
</div>
<p class="para">
The above form displays a text input box (named <i><tt class="parameter">q</tt></i>
),
and a submit button. When the submit button is clicked, the form will be
sent to the page referred to by <i>action</i>.
</p>
<p class="para">
Here's where it starts to look different from your web application's point
of view. In a normal HTML form, the data would be sent as
<i>application/x-www-form-urlencoded</i>, in the XForms world
however, this information is sent as <acronym title="eXtensible Markup Language">XML</acronym> formatted data.
</p>
<p class="para">
If you're choosing to work with XForms then you probably want that data as
<acronym title="eXtensible Markup Language">XML</acronym>, in that case, look in <var class="varname"><a href="reserved.variables.httprawpostdata.php" class="classname">$HTTP_RAW_POST_DATA</a></var> where
you'll find the <acronym title="eXtensible Markup Language">XML</acronym> document generated by the browser which you can pass
into your favorite <acronym title="eXtensible Stylesheet Language Transformations">XSLT</acronym> engine or document parser.
</p>
<p class="para">
If you're not interested in formatting and just want your data to be loaded
into the traditional <var class="varname"><a href="reserved.variables.post.php" class="classname">$_POST</a></var> variable, you can instruct
the client browser to send it as <i>application/x-www-form-urlencoded</i>
by changing the <i><tt class="parameter">method</tt></i>
attribute to
<em class="emphasis">urlencoded-post</em>.
</p>
<div class="example">
<p><b>Example #2 Using an XForm to populate <var class="varname"><a href="reserved.variables.post.php" class="classname">$_POST</a></var></b></p>
<div class="example-contents programlisting">
<div class="htmlcode"><pre class="htmlcode"><h:html xmlns:h="http://www.w3.org/1999/xhtml"
xmlns="http://www.w3.org/2002/xforms">
<h:head>
<h:title>Search</h:title>
<model>
<submission action="http://example.com/search"
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></pre>
</div>
</div>
</div>
<blockquote><p><b class="note">Note</b>:
<span class="simpara">
As of this writing, many browsers do not support XForms.
Check your browser version if the above examples fails.
</span>
</p></blockquote>
</div>
<?php manual_footer(); ?>