Skip to content
Hub Nexus

No author yetClaim it

Version 1Updated 2 min read

Support

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.

Get each new page of

XForms

Following means one email when a page is added, nothing when a page changes.

Following means one email when a page is added, nothing when a page changes.

Comments

Spinner Logo

Next in XForms

CC BY-SA 4.0
Add the following instance to your model: xmlns="" id="log"> log initialized Whenever you want to see an event, just add an action that appends an event to the end of the log: ev:event="xforms-deselect"> nodeset="instance('log')/event" at="last()" position="after" /> ref="instance('log')/event[last(
CC BY-SA 4.0
First you need to give the control you want to receive the first keystroke event an **id** attribute. For example: id="first-field"> Search The next step is to use the **xforms-ready** event to set the focus to this field using the **setfocus** element. These initial actions are usually placed at th
CC BY-SA 4.0
id="tab-bar"> appearance="minimal"> Tab One case="case-1" ev:event="DOMActivate" /> appearance="minimal"> Tab Two case="case-2" ev:event="DOMActivate" /> appearance="minimal"> Tab Three case="case-3" ev:event="DOMActivate" /> id="case-1"> ev:event="xforms-select"> nodeset="instance('log')/event" at=
CC BY-SA 4.0
Here is the code for the action itself: ev:event="xforms-delete" ev:observer="people" if="not(person)"> origin="instance('person-template')" context="."/> This says to watch the **people** instance and if there is not a person in the people instance then insert one using the person-template instance
CC BY-SA 4.0
But this creates problems when referencing data elements without specifying what model the instance is part of. Note in the example below the group element encloses the output for each model. ## Sample Program xmlns=" xmlns:xf=" xmlns:foobar=" Binds to Multiple Instances in Multiple Models type="tex
CC BY-SA 4.0
Here is a simple example of how to get a list of repeating data elements out to your screen. This is done using the repeat tag and the nodeset attribute. You use the nodeset to specify where you want to begin your listing in the model. In this case we are just using a model embedded into the page.