Quelque chose à améliorer ? Proposez une modification.
Dans XForms · page 41 sur 137
Motivation
After a save, you want to display a line at the end of your form to confirm that the results have been saved to the server. You also want to notify the user of any errors after a save.
Method
We will use the submission element to save the data and return the save results. We will use the to show either a success (in green) or a failure (in red).
xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms" xmlns:xf="http://www.w3.org/2002/xforms">
Save Test
xmlns="" id="save-data">
form-id="unit-tests-save-test">
Dan
McCreary
xmlns="" id="save-results">
No Save Results Yet
id="save-submission" ref="instance('save-data')"
method="post" resource="http://localhost:8088/exist/rest/db/apps/grants/scripts/save.xq"
replace="instance"
instance="save-results">
ev:event="xforms-submit-done">
Save Done
ev:event="xforms-submit-error">
Save Failed
id="save-submission-see-save-results" ref="instance('save-data')"
method="post" resource="http://localhost:8088/exist/rest/db/apps/grants/scripts/save.xq" replace="instance"
instance="save-results">
ev:event="xforms-submit-done">
Save Done
ev:event="xforms-submit-error">
Save Failed
type="text/css">
.success {color: green; background-color: lightgreen;}
.failure {color: red; background-color: pink;}
ref="first-name">
First name:
ref="last-name">
Last name:
href="http://localhost:8088/exist/rest/db/apps/xforms/scripts/save.xq">Save URL
class="save-controls">
submission="save-submission" appearance="xxforms:primary" class="button-margin-top">
Save and Validate
submission="save-submission-see-save-results" class="button-margin-top">
Save See Save Results
ref="instance('save-results')/.[@code='200']">
class="success">
ref="instance('save-results')//message"/>
ref="instance('save-results')/.[@code='400']">
class="failure">
ref="instance('save-results')//message"/>
Sample XQuery
xquery version "1.0";
import module namespace config= "http://danmccreary.com/config" at "../modules/config.xqm";
declare namespace xs="http://www.w3.org/2001/XMLSchema";
declare namespace xf="http://www.w3.org/2002/xforms";
declare namespace dc="http://gov/grantsolutions/dc";
let $log := util:log-system-out('running save.xq')
(: get-data() returns the document node. We want the root node :)
let $formdata := request:get-data()/*
(: check to make sure we have valid post data :)
return
if (not($formdata))
then code="400">No Post Data
else
let save-data-collection := concat(config:app-home-collection, '/save-data')
let $form-id :=
if (exists($formdata/@code))
then $formdata/@code/string()
else
if (exists($formdata/@form-id))
then $formdata/@form-id/string()
else 'unknown-form-id'
let file-name := concat(form-id, '.xml')
let path-name := concat(save-data-collection, '/', $file-name)
let $overwrite :=
if (doc-available($path-name))
then true()
else false()
let store := xmldb:store(save-data-collection, $file-name, $formdata)
return
code="200">
{if ($overwrite)
then Document updated at {$path-name}
else New document saved to {$path-name}
}
Where this page came from
This page was imported from Wikibooks. From “XForms” on Wikibooks, by its contributors, under CC BY-SA 4.0. Changed here: set as a page; navigation and edit links left out; each image under its own licence, credited in its caption.
Nobody has written it yet — it is the source material at a new address, which is why search engines are asked to skip it and why no one earns from it. It is up for grabs: take it on, and it is yours to rewrite and to earn from.
Dans ces publicationsXForms
Licence : CC BY-SA 4.0 · Adapté de en.wikibooks.org
1
0
0
0

commentaires






