DB Record Loader - On No/Empty Param Passed

Rocketeer 30 Jul, 2013
I'm new to ChronoForms, so my apologies if I'm getting some of the terminology wrong!

I'm using Joomla! 3.1.4, with Chronoforms_V4_stable_J3.0 Component and Mod_Chronoforms_J3.0_V4_RC3.5.3 Module.

I've found that the DB Record Loader isn't handling the "On No/Empty Param Passed" result correctly.

As far as I can tell, the DB Record Loader is supposed to have 3 possible "results" - "On Record Found", "On Empty Result" and "On No/Empty Param Passed"

If the Param (e.g. ?option=com_chronoforms&tmpl=component&chronoform=create&token=1) is in the URL with a valid, the DB Record loader correctly.
If the Param is present, but doesn't match a record in the database, the "Not found" action is taken.
If the Param is present, but empty (e.g. ?option=com_chronoforms&tmpl=component&chronoform=create&token), the "No/Empty Param Passed" action is taken
However, if the Param is missing entirely (e.g. ?option=com_chronoforms&tmpl=component&chronoform=create), it acts as if the parameter is present, but generates invalid SQL (the classic 1064 with an empty WHERE clause).

Based on the text "No/Empty Param Passed", I expect the missing parameter to be treated exactly the same as the empty parameter.

Any thoughts from the community/support?
Rocketeer 30 Jul, 2013
Okay, I've also found a work-around that might be useful for others...

Before the "DB Record Loader" event, add a "Custom Code" event, and use the following code. Replace "token" with whatever you actually use as the variable name for your lookup.
<?php
$tmpForm = CFChronoForm::getInstance($this->form_name);
if (!array_key_exists('token', $tmpForm->data)) $tmpForm->data['token'] = '';
?>


This creates an entry for your "token" in the form's data array (if it wasn't already there), and therefore prevents the "No Param" scenario from ever happening - only the (working) "Empty Param" outcome is possible.
GreyHead 30 Jul, 2013
Hi Rocketeer,

That looks like a bug to me.

You can simplify your fix a little by working directly with the $form->data array:
<?php
if ( !isset($form->data['token']) ) {
  $form->data['token'] = '';
}
?>

Bob
This topic is locked and no more replies can be posted.