Confirming the data
Let us assume that we have entered correct data, for example:
This is then sent to the second stage of the flow script which sends the following form:
context://dosumentation/addUserTest-2.xml
<pf:form id="addUserTestForm"
flow="addUserTest"
continuation="{flow:continuation.id}"
session="{flow:__flowId}" >
<pf:label>You input the following information:</pf:label>
<pf:output ref="username">
<pf:label>Username:</pf:label>
<pf:value>{flow:username}</pf:value>
</pf:output>
<pf:output ref="fullname">
<pf:label>Full name:</pf:label>
<pf:value>{flow:fullname}</pf:value>
</pf:output>
<pf:submit class="button" id="prev">
<pf:label>Back</pf:label>
<pf:hint>Go to previous page</pf:hint>
</pf:submit>
<pf:submit class="button" id="next">
<pf:label>Confirm</pf:label>
<pf:hint>Confirm new user</pf:hint>
</pf:submit>
</pf:form>
which will display:
Adding the data to a file can be carried out in a further stage which uses the SourceWritingTransformer. In those
immortal words, "I will leave this as a simple exercise for the reader", subtext for "I haven't time to
document it yet".
I have set up an example above so that you can see how it works (less the SourceWriting stage. The example below
has the following extra code:
context://dosumentation/addUserTest-3.xml
<pf:form id="addUserTestForm"
flow="addUserTest"
continuation="{flow:continuation.id}"
session="{flow:__flowId}" >
<pf:label>You input the following information:</pf:label>
<pf:output ref="username">
<pf:label>Username:</pf:label>
<pf:value>{flow:username}</pf:value>
</pf:output>
<pf:output ref="fullname">
<pf:label>Full name:</pf:label>
<pf:value>{flow:fullname}</pf:value>
</pf:output>
<pf:submit class="button" id="next">
<pf:label>Finished</pf:label>
<pf:hint>Back to documentation home page</pf:hint>
</pf:submit>
</pf:form>
context://resources/scripts/AddUserTest.php
public function add()
{
global $gModules;
$requestParameterModule = $gModules[ 'request-param' ];
$finished = false;
while ( !$finished ) {
$errors = false;
switch ( $this->gContinuation ) {
case 0 :
$this->sendPage(
"addUserTest-1.html", // The page to send to the client
$this->gAddFormTestModel, // The current data model to send
++$this->gContinuation, // The continuation link for the next stage
$this->gViolations ); // Array of errors (keyed by data model keys)
$finished = true;
break;
case 1 :
foreach ( $this->dataRequired as $key => $msg ) {
if ( !isset( $this->gAddFormTestModel[ $key ] ) or
strlen( $this->gAddFormTestModel[ $key ] ) == 0 ) {
$this->gViolations[ $key ] = $msg;
$errors = true;
}
}
// Now check for remaining errors. Adjust the order of the checks to suit local conditions.
// The last check is what is displayed.
if ( $errors === false ) {
if ( strlen( $this->gAddFormTestModel[ 'password' ] ) < 8 ) {
$this->gViolations[ 'password' ] = "Password must be more than 8 characters long";
$errors = true;
}
if ( $this->gAddFormTestModel[ 'password' ] !=
$this->gAddFormTestModel[ 'passwordCheck' ] ) {
$this->gViolations[ 'password' ] = "Password does not check";
$errors = true;
}
}
if ( $errors ) {
// Set back to previous stage and go round again (sends first page again with violations
$this->gContinuation--;
$finished = false;
} else {
// No errors so send next page
$this->sendPage(
"addUserTest-2.html",
$this->gAddFormTestModel,
++$this->gContinuation,
$this->gViolations );
$finished = true;
}
break;
case 2 :
// No errors to record from optional data so send next page
$this->sendPage(
"addUserTest-3.html",
$this->gAddFormTestModel,
++$this->gContinuation,
$this->gViolations );
$finished = true;
break;
case 3 :
// Data confirmed return to documentation index
$this->sendPage(
"documentation.html",
$this->gAddFormTestModel,
++$this->gContinuation,
$this->gViolations );
$finished = true;
break;
}
}
}
Copyright 2006 – 2023 Hugh Field-Richards. All Rights Reserved.