Adding Composers (continued)

Confirming the Entered Data

The first thing is to check the data being entered. We have to add the next case in the continuations to check on the entered data:

resources/scripts/AddComposer.php
class AddComposer extends Continuations { /** Logger instance for this class */ private $gLogger; private $gAddComposerModel = array ( "name" => "", "firstNames" => "", "birth" => "", "death" => "", ); private $dataRequired = array ( "name" => "Must enter a composer's name", ); ... // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* --> // -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* --> /** */ function add() { global $gModules; $this->gLogger->debug( "Adding entry, continuation: " . $this->gContinuation ); $requestParameterModule = $gModules[ 'request-param' ]; $this->gViolations = array(); $finished = false; while ( !$finished ) { $errors = false; switch ( $this->gContinuation ) { case 0 : $this->sendPage( "addComposer-1.html", // The page to send to the client $this->gAddComposerModel, // 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 : // Error processing here // First I have to check that there are contents in the required fields. I could leave // out the "isset" but some PHP systems will have strict error checking // and produce extraneous error messages on the page. foreach ( $this->dataRequired as $key => $msg ) { if ( !isset( $this->gAddComposerModel[ $key ] ) or strlen( $this->gAddComposerModel[ $key ] ) == 0 ) { $this->gViolations[ $key ] = $msg; $errors = true; } } // Now check for remaining errors. Adjust the order of the checks // to suit local conditions. if ( $errors === false ) { if ( $this->gAddComposerModel[ 'birth' ] >= $this->gAddComposerModel[ 'death' ] and $this->gAddComposerModel[ 'birth' ] != "" and $this->gAddComposerModel[ 'death' ] != "" ) { $this->gViolations[ 'birth' ] = "Birth is later than death"; $errors = true; } } if ( $errors ) { $this->gContinuation--; $finished = false; } else { // No errors so send next page $this->sendPage( "addComposer-2.html", $this->gAddComposerModel, ++$this->gContinuation, $this->gViolations ); $finished = true; } break; } } }

If an error occurs (such as a blank form) then the following will be output:

Confirm Add Composer Form

Assuming that there are no errors the flowscript redirects to the page, addComposer-2.html. The sitemap does not need to change but the XML file is:

/examples/sql/addComposer-2.xml
<page:content> <t:heading level="1">SQL Add Composer</t:heading> <pf:form id="addComposerForm" flow="addComposer" continuation="{flow:continuation.id}" session="{flow:__flowId}"> <pf:label>Press confirm to accept new composer:</pf:label> <pf:output ref="name"> <pf:label>Composer name:</pf:label> <pf:value>{flow:name}</pf:value> </pf:output> <pf:output ref="firstNames"> <pf:label>First names:</pf:label> <pf:value>{flow:firstNames}</pf:value> </pf:output> <pf:output ref="birth"> <pf:label>Birth date:</pf:label> <pf:value>{flow:birth}</pf:value> </pf:output> <pf:output ref="death"> <pf:label>Death date:</pf:label> <pf:value>{flow:death}</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 composer</pf:hint> </pf:submit> </pf:form> <t:p> <link:link type="uri" ref="/examples/sql/sql.html">Return to SQL index</link:link> </t:p> <t:p><link:link type="uri" ref="/examples/sql/logout.html">Logout</link:link> from admin pages.</t:p> </page:content>

which provides a confirmation page. Entering the following data:

Gives the output:

The next section shows how to write this information into the database.

Copyright 2006 — 2010 Hugh Field-Richards. All Rights Reserved.