Getting Previously Entered Values
From FacileWiki
Here's the scenario:
A User enters some data into an example Form-A, hits the submit button. When the submit button is hit, a few things happen in this order:
- The form is validated using the 'after submit' script (we're using javascript here)
- Any 'Before Submit' Pieces of code are executed (now we're using php)
- The record and subrecord tables (log file) are inserted into the database
- The 'End Submit' Piece is executed (also php).
For this example, we have redirected in above step 4 to another seperate Form-B. Form-B will return to our original Form-A. Form-A is required to pull the values from the Facile Forms subrecord table and show them again to the user, thereby saving him/her the trouble of rekeying those values.
Premise
We need to uniquely identify each record in the subrecord table. For my example scenario, Form-A calculated a unique random number called 'record_id' which is saved in the subrecord table along with all the other fields entered.
This means that :
- Form-A must Pass to Form-B the value of record-id as a GET/POST parameter in that 'End Submit' piece
- Form-B must return via a GET/POST parameter the value of record-id
- Form-A must check for the presence of the parameter in the 'Before Form' piece and act appropriately.
Before Form Code
Here is the Before Form Code (this is php but you don't need the <?php ?> in the Before Form area. Included is an illustration for setting a text field with setValue, a select list with setSelected, a radio button array with setChecked and a check box using setChecked:
NOTE: The case statement contains unique datanames that would have to be changed for a real form.
/* Before Form Piece for retrieving all the subrecords from a previous visit */
$this->execPieceByName('ff_InitLib');
global $record_id;
global $query, $rows;
$record_id = ff_getParam('ff_rid');
echo "Record ID is " . $record_id . "<br>\n"; /* <--showing the rec id for debug purposes */
/* Get the key id number from the log record here using record_id */
if ($record_id != '') {
$query = "select record from #__facileforms_subrecords where value = '";
$query .= $record_id;
$query .= "' and name = 'sv_recordid'";
echo "Query one is " . $query . "<br>\n"; /*<---showing the query for debugging purposes */
$dbrec_id = ff_selectValue($query);
/* Now get all the values from the log file with proper id*/
$query = "select name, value as valx from #__facileforms_subrecords where record = '";
$query .= $dbrec_id;
$query .= "'";
$rows = ff_select($query);
$cnt = count($rows);
echo " Query returned " . $cnt . " rows " . "<br>\n"; /*<--show the 2nd query for debug */
foreach ($rows as $row ) {
switch ($row->name) { /* The echo's are for debugging purposes only */
case 'res_addr' : echo "Found res_addr here and value is " . $row->valx . "<br>\n";
ff_setChecked('radio_btn',$row->valx);
break;
case 'First_Name' : echo "Found First_Name and value is " . $row->valx . "<br>\n";
ff_setValue('text_box', $row->valx);
break;
case 'Birth_month' : echo "Found Birth Month and value is " . $row->valx . "<br>\n";
ff_setSelected('select_list', $row->valx);
break;
case 'best_time_cm' : echo "Found best_time here and value is " . $row->valx . "<br>\n";
ff_setChecked('check_box',$row->valx);
break;
default : break;
} // switch
}//for
}