Views
Submission
From PicoForms
Data collection has become extremely important for organizations for analyzing the business processes and arriving at the right decisions. Many organizations rely on websites and portals as one of the easiest means for collecting data from the end users and website visitors.
Unlike HTML where data collection is limited to the name-value pairs format, XForms offers several sophisticated options for submitting and receiving form data. XForms is considered best for sending and receiving XML data.
Contents |
[edit] Submission in XForms
In XForms, the <submission> element is used for executing submission of data.
For submitting an instance a <submission> element must be created that will define the submission . In addition the <submission> element also specifies the destination where the data should go (through the action attribute) and what data should go to the destination.
Example:
<?xml version="1.0" encoding="ASCII"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/XForms">
<head>
<title>My Favorite Writers</title>
<xforms:model id="model_writers">
<xforms:instance xmlns="">
<writers>
<writer>
<name></name>
<title></title>
<year></year>
</writer>
</writers>
</xforms:instance>
<xforms:submission id="submit_model_writers"
action="http://favorite_writers.com/cgi-bin/writers"
method="get"/>'
</xforms:model>
</head>
<body>
In the above example, the form is identified by the submission id="submit_model_writers" attribute; the action="http://favorite_writers.com/cgi-bin/writers attribute defines the URL - the destination - where the data should be sent on submission of the form; and the method used while submitting the data is defined by the method="get" attribute.
[edit] When does submission occur
In simple terms, a submission takes place when a “Submit” button is clicked.
However, if we state this formally, a submission is commenced when the xforms-submit event reaches the submission element.
Submission is specified by a separate event to request submission in different situations such as on pressing the “Enter” button or, on meeting other predefined conditions.
The submission event can explicitly be sent out with the XForms Action send. The xforms-submit event is dispatched by the form control named submit and provides the click-to-submit feature to the event. At other instances the submit control behaves exactly like the trigger.
[edit] When Submission Fails
The xforms-submit event is dispatched to initiate submission. However, it is not guaranteed that merely dispatching the xforms-submit event will complete the submission successfully.
Submission fails on several occasions; and each time the submission fails a notifications event is sent to the user.
- When the event fails to reach its target element, submission fails. There are many reasons when an event fails to actually reach its target, and sometimes an event is deliberately stopped from reaching its mark. So if the event is obstructed along its way, the submission will fail.
- A submission may fail if multiple submissions are in progress simultaneously on the same XForms model.
- If the instance data does not validate, the submission will fail. When data is fed into the form, the submit processing performs complete validation of the form data, and if the data does not validate the XForms processor will stop the submission by notifying the invalid form controls.
- Submission can also fail due to external problems encountered during the submit process, such as server crash, when feeding data is not possible. In such situations submission fails and the user is notified.
When a submit is in progress, either of the two things will result:
- Dispatch of an xforms-submit-done event to the originating submission element will occur, or
- Dispatch of an xforms-submit-error event to the model element containing the originating submission element will occur
[edit] Advantages of XForms Submission
In XForms, instance data of less than the full document can be submitted.
Complex data submission in XForms can be managed by dividing them into multiple XForms models. For example, a web page having two forms – one for log in and another for newsletter registration – can have these forms in separate model elements. When the two forms are divided into two separate model elements, separate instant data will be submitted by each of the XForms Model.
[edit] What to Submit in XForms
If there is more than one form in a web page, a highly effective method for submission is to divide the forms into separate model elements. If any temporary data is used only during the form processing and the data is not required during the actual submission, using multiple instances within the same model will be more helpful than using multiple models for the submission. The following example illustrates this case.
<xforms:model>
<xforms:instance id="submitme">
<my:investment>
<my:amount>2500.00</my:amount>
<my:interest/>
</my:investment>
</xforms:instance>
<xforms:bind nodeset="/my:investment/my:interest" calculate="../my:amount * instance ('interestrate')"/>
<xforms:instance id="interestrate" src="interest.xml"/>
</xforms:model>
Here the data intended to be submitted is the primary data that has the identifier submitme. The data with the identifier interestrate is the secondary instance data that is loaded from another XML document. It is a separate document that has a single element <interest>0.8</interest> with a decimal interest rate as its content. As the interest rate comes from a separate source file interest.xml, different rates can be used in the form by only replacing the source file. This way the calculation can be separated from the other parts of the form.
In the example, multiplication of two values are performed by the calculate expression, where one value - /my:amount - is an element node that gives a numeric value for the amount of investment, and the other value - instance('interestrate') – takes the instance data associated with the ID interestrate and returns the top-level element node. The resulting value is given by the element node /my:investment/my:interest.
After selecting an instance document for submission, additional methods are available in XForms for cutting the XML tree shorter, such as by specifying a sub-tree of the instance data. The larger XML tree is cut shorter by specifying a sub-tree in two different ways – either using the ref attribute or using the bind attribute.
In the data that has been submitted, a node with a relevant property evaluating to be false will be absent. Accordingly, a node being excluded from the XML tree will have all its descendent nodes including child elements, attributes, text, etc. excluded from the tree, whatever relevant property the descendent node may have.
