Deleting Composers (continued)

Confirm Data Form

We need to confirm that the selected composer is the right one, so the PForm to do this is:

<page:content> <pf:form id="deleteComposerForm" flow="deleteComposer" continuation="{}" session="{flow:__flowId}"> <pf:label>Press confirm to delete composer:</pf:label> <execute-query xmlns=""> <query name="confirmDeleteComposer" database="composers">select * from composer where name = '{flow:selectDeleteComposer}'</query> </execute-query> <execute-query xmlns=""> <query name="getComposerId" database="composers">select id from composer where name = '{flow:selectDeleteComposer}'</query> </execute-query> <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 delete 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>

There are two SQL queries here: the composers name for confirmation, and the identity to use for the actual delete command. The former will be used to display a simple text filed and the latter will be a hidden field.

Extending the Flow Script

The flow script needs to be changed to handle this case and detect errors (nothing selected):

function delete() { global $gModules; $this->gLogger->debug( "Delete composer, continuation: " . $this->gContinuation ); $this->gViolations = array(); $finished = false; while ( !$finished ) { $this->gLogger->debug( "Processing: " . $this->gContinuation ); $errors = false; switch ( $this->gContinuation ) { case 0 : $this->sendPage( "deleteComposer-1.html", // The page to send to the client $this->gDeleteComposerModel, // 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. Only have to check whether a composer has been selected. if ( strlen( $this->gDeleteComposerModel[ 'selectDeleteComposer' ] ) == 0 ) { $this->gViolations[ 'selectDeleteComposer' ] = "Need a composer to delete"; $errors = true; } if ( $errors ) { $this->gContinuation--; $finished = false; } else { $this->sendPage( "deleteComposer-2.html", $this->gDeleteComposerModel, ++$this->gContinuation, $this->gViolations ); $finished = true; } break; case 2 : ... } // switch } // while } // function delete()

The same sitemap matcher is used as before. After selecting the composer and clicking "Next" the extracted data returned from the database:

<default:row-set xmlns="" nrofrows="1" name="confirmDeleteComposer"> <default:row> <default:id>17</default:id> <default:name>Elgar</default:name> <default:forenames>Edward</default:forenames> <default:birth>1857-06-02</default:birth> <default:death>1934-02-23</default:death> </default:row> </default:row-set> <default:row-set xmlns="" nrofrows="1" name="getComposerId"> <default:row> <default:id>17</default:id> </default:row> </default:row-set>

This is transformed into

<pf:output appearance="full" ref="confirmDeleteComposer"> <pf:label>Composer name:</pf:label> <pf:value>Elgar, Edward</pf:value> </pf:output> <pf:hidden ref="composerId"> <pf:value>17</pf:value> </pf:hidden>

When processed this form appears as:

The next section shows how to process the SQL command for deleting a composer.

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