<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Dealing with XForms</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.sessions.html">Sessions</a></div> <div class="next" style="text-align: right; float: right;"><a href="features.file-upload.html">Handling file uploads</a></div> <div class="up"><a href="features.html">Features</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="features.xforms" class="chapter"> <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">» <em>XForms for HTML Authors</em></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" id="example-354"> <p><strong>Example #1 A simple XForms search form</strong></p> <div class="example-contents"> <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 <em><code class="parameter">q</code></em>), and a submit button. When the submit button is clicked, the form will be sent to the page referred to by <em>action</em>. </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 <em>application/x-www-form-urlencoded</em>, 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"><var class="varname"><a href="reserved.variables.httprawpostdata.html" class="classname">$HTTP_RAW_POST_DATA</a></var></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"><var class="varname"><a href="reserved.variables.post.html" class="classname">$_POST</a></var></var> variable, you can instruct the client browser to send it as <em>application/x-www-form-urlencoded</em> by changing the <em><code class="parameter">method</code></em> attribute to <em class="emphasis">urlencoded-post</em>. </p> <div class="example" id="example-355"> <p><strong>Example #2 Using an XForm to populate <var class="varname"><var class="varname"><a href="reserved.variables.post.html" class="classname">$_POST</a></var></var></strong></p> <div class="example-contents"> <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 class="note"><p><strong class="note">Note</strong>: <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> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="features.sessions.html">Sessions</a></div> <div class="next" style="text-align: right; float: right;"><a href="features.file-upload.html">Handling file uploads</a></div> <div class="up"><a href="features.html">Features</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>