XForms Basics, Part 2 - A Custom Job (Page 4 of 6 )
In addition to the attributes you've already seen, the <xforms:submission> element also comes with a bunch of others, which can assist in customizing the manner in which the form data is submitted. Here's a brief list:
ref - Specifies the node to use as root when submitting instance data, defaults to /.
version - Specifies XML version to use when submitting form data.
indent - Toggles indenting of XML data in form submission.
encoding - Specifies XML encoding to use when submitting form data.
omit-xml-declaration - Toggles XML declaration when submitting form data.
standalone - Toggles standalone declaration when submitting form data.
replace - Specifies what to do with the response to the submission.
Consider the following example, which demonstrates some of these in action:
<html xmlns=<A href="http://www.w3.org/1999/xhtml">http://www.w3.org/1999/xhtml</A>
xmlns:xforms="http://www.w3.org/2002/xforms/cr">
<head>
<!-- form model -->
<xforms:model id="information">
<xforms:instance>
<user>
<name />
<email />
<age />
</user>
</xforms:instance>
<xforms:submission id="submit"
ref="/user/name" action="/tmp/user.xml"
method="put" indent="yes"
omit-xml-declaration="no" />
</xforms:model>
<basefont face="Arial">
</head>
<body>
<!-- define interface controls -->
<table cellspacing="5" cellpadding="5"
border="0">
<tr>
<td>
<xforms:input id="txtname"
model="information" ref="/user/name">
<xforms:label>Name</xforms:label>
<xforms:hint>Enter your name
here</xforms:hint>
</xforms:input>
</td>
</tr>
<tr>
<td>
<xforms:input id="txtemail"
model="information" ref="/user/email">
<xforms:label>Email address
</xforms:label>
<xforms:hint>Enter your email address
here</xforms:hint>
</xforms:input>
</td>
<td>
<xforms:input id="txtage"
model="information" ref="/user/age">
<xforms:label>Age</xforms:label>
<xforms:hint>Enter your age
here</xforms:hint>
</xforms:input>
</td>
</table>
<xforms:submit submission="submit">
<xforms:label>Save</xforms:label>
<xforms:hint>Save the information
entered above to a local file</xforms:hint>
</xforms:submit>
</body>
</html>
In this case, I've explicitly told the XForms processor to include the XML declaration in the final form submission, but to only include that part of the instance data tree beginning with the element <name>. Here's the output:
[output]
<?xml version="1.0" encoding="ISO-8859-1"?>
<name>Harish</name>
[/output]
It's important to note, also, that XForms supports submitting data in more than just PUT and POST methods, and that if you really need to, you can even replicate the behavior of traditional HTML forms by submitting your data in the standard name=value format. The method attribute of the <xforms:submission> element can take any of the values "post", "get", "put", "multipart-post", and "form-data-post." Take a look at the specification to see what each one of these does.
Next: Not My Type >>
More XML Articles
More By Harish Kamath, (c) Melonfire