Next Sequence and Checking for Errors

When the "next" button is pressed it sends the form data with the request:

http://<hostname>documentation/addUserTest.kont?__session=1174930335

The request is made up of the forms <form> tag's @flow attribute (addUserTest) and the "kont" extension. The session variable is added by the Continuations software. This request matches the pipeline:

context://documentation/sitemap.xmap
<map:match pattern="addUserTest.kont"> <map:call function="AddUserTest::add"/> </map:match> </map:pipeline>

which runs the add method we saw previously. However his time it is directed to the 2 case of the switch statement which now has to output the next form in the sequence. If data is to be checked, this is where it is done. How you do this is up to you but the following seems to work quite well for this case. First declare a violations array:

context://resources/scripts/AddUserTest.php
<?php require_once( PHP_DIR . "/flows/Continuations.php" ); class AddUserTest extends Continuations { /** Logger instance for this class */ private $gLogger; private $gAddFormTestModel = array ( "username" => "", "password" => "", "passwordCheck" => "", "fullname" => "", ); private $dataRequired = array ( "username" => "Must enter a username", "password" => "Must enter a password", "passwordCheck" => "Must enter a password check", ); function __construct() { $this->gLogger =& LoggerManager::getLogger( __CLASS__ ); parent::__construct( $this->gAddFormTestModel ); }

Next add the actual error check to the case 2 of the continuations selector:

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; ... } } }

If we do not fill any fields in and submit the form then the first page is sent again with the violations marked:

The next page describes the confirmation of data.

Copyright 2006 – 2023 Hugh Field-Richards. All Rights Reserved.