Can I test my code in Custom Code action?

debug and test custom code in ChronoForms.

Overview

The issue arises when trying to test and debug custom code, particularly to verify SQL query results and use those values in form fields.
Use Joomla's application messaging or direct output to display variable contents for debugging. Ensure correct Joomla database methods, like loadAssoc, are used to retrieve data and merge it into the form data array.

Answered
Je JeLu 07 Feb, 2014
Hi all!
Can I test when a Custom Code runs and what values that comes out of My SQL-query?

I am not sure what is wrong in my code and need to debug it further than the Debug action in CFv4

//JeLu
Je JeLu 07 Feb, 2014
I have already read that FAQ 😉
Gr GreyHead 07 Feb, 2014
Hi Jelu,

I use code like
$app =& JFactory::getApplication();
$app->enqueuemessage('$var: '.print_r($var, true).'<hr />');
or
echo'<div>$var: '.print_r($var, true).'</div>';
to add debug code almost anywhere.

The first version shows a system message on the next page load, the second just dumps a <div> into the current output.

Bob
Je JeLu 08 Feb, 2014
Thank You!

I get the info I want from my DB. Now I wonder if I can use that value in default value. I tried
<?php echo '$data'; ?>

But it only shows $data and then I wonder if it is not possible to do it like this?

//JeLu
Gr GreyHead 09 Feb, 2014
Hi JeLu,

ChronoForms puts data into the $form->data array as far as I know $data will be empty unless you have specifically set a value.

Bob
Je JeLu 10 Feb, 2014
Hi!

I have this code in a Custom Code-action:
[code][/<?php
$user =& JFactory::getUser();
$db =& JFactory::getDBO();

$query = "
SELECT `cf_id`, `cf_user_id`, `foo
FROM `#__chronoforms_data`
WHERE `cf_user_id` = '{$user->id}' ORDER BY `cf_id` DESC LIMIT 1
";
$db->setQuery($query);
$data = $db->loadArray();
$form->data = array_merge($form->data, $data);
$app =& JFactory::getApplication();
$app->enqueuemessage('$data: '.print_r($data, true).'<hr />');
?>code]

Now when the check runs, $data is empty.

In Default Field Value I have put this:

<?php  '.print_r($form->data->foo, true).'; ?>


I think that SQL-query is correct but it is not merged with $form->data?!

I have this Custom Code in an Authenticator-action->Allowed. In Allowed there is first a Multi-Page action second a Custom Code action and finally a Show HTML action. I have tested the Custom Code- action to run in On Load event too but that did not help.

I have my Custom Code in View mode. If I set it in Controller Mode the Array in Debug becomes empty at that page.

//JeLu
Gr GreyHead 10 Feb, 2014
Answer
Hi JeLu,

Is $db->loadArray() a valid Joomla! Database method? I'm not sure that it is.

Bob
Je JeLu 10 Feb, 2014
Hi!

You are sooo right. It should be loadAssoc in Joomla 3.2.

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