Hi Les,
I do this by using my
Unique ID [GH] action in the OnSubmit event of the first form then saving the resulting ID (a random text sequence) into the Joomla! User session, and/or into a 30 day cookie.
Then you can check the session on each succeeding form - if there is no ID then return to the first form; if there is one add it to a hidden input in the form.
The cookie is only useful if you think that users may take a longer time to complete the form steps. The user session is destroyed after 15 minutes of inactivity (you can lengthen the this if necessary). A cookie will only work if the user returns on the same computer though.
Here's an example of the code to do this in ChronoForms v3 - the first part is now built into the action for CFv4.
OnSubmit code for Form 1, the 'chronoforms_lijsten' table is just used to store a list of IDs.
$db =& JFactory::getDBO();
$lijst_id = JRequest::getString('lijst_id', '', 'post');
if ( !$lijst_id ) {
do {
$lijst_id = generateIdent('9999A');
$query = "
SELECT COUNT(*)
FROM `#__chronoforms_lijsten`
WHERE `lijst_id` = '{$lijst_id}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
} while ($count != 0);
$lijst_id = 'LSR'.$lijst_id;
}
$session = JFactory::getSession();
$session->set('lijst_id', $lijst_id);
// saved lijst_id to cookie for 30 days
setcookie('lijst_id', $lijst_id, time()+60*60*24*30);
JRequest::setVar('lijst_id', $lijst_id, 'post');
// save lijst_id to database
if ( !class_exists('Tablechronoforms_lijsten') ) {
class Tablechronoforms_lijsten extends JTable {
var $cf_id = null;
var $uid = null;
var $recordtime = null;
var $ipaddress = null;
var $cf_user_id = null;
var $lijst_id = null;
function __construct( &$database ) {
parent::__construct( 'jos_chronoforms_lijsten', 'cf_id', $database );
}
}
}
and the code to check in the ON Load event of the later forms
$lijst_id = JRequest::getString('lijst_id', '', 'cookie');
$session = JFactory::getSession();
$lijst_id = $session->get('lijst_id', $lijst_id);
if ( !$lijst_id ) {
$mainframe =& JFactory::getApplication();
$mainframe->redirect('index.php?option=com_chronocontact&chronoformname=gedeelte_h1');
}
Bob