How to debug a PHP element validation plugin ?

Incremental

Member
I've tried to put some echo strings, but nothing appears and I get a JSON error in the popup form :
"SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data"

I've also tried to put the following code found in the forum :
// Include the JLog class.
jimport('joomla.log.log');
// Add the logger.
JLog::addLogger(array('text_file' => 'fabrik.log.php'));
// Start logging...
JLog::add('your message here', JLog::NOTICE, 'com_fabrik');
in my PHP, but no file is created.

Any help would be great !
 
Thanks cheesegrits,
I already use Firebug, but I can't see my debug traces with it.
My purpose is at validation, to check if an ID is valid because existing in another table.
Thus I used a PHP validation plugin for the element.
I put the following code :
PHP:
// Get the form field's value:
$IDinput = '{contacts___ContactsFormID}';
dump($IDinput, " : IDinput");
 
// Get the db object
$db =JFactory::getDbo();
 
// Quote the values for security reasons
$IDinput = $db->quote($IDinput);
 
// Build the query
$query = $db->getQuery(true);
$query
    ->select('COUNT(*)')
    ->from('ContactsParams')
    ->where('ID = '. $IDinput);
$db->setQuery($query);
 
// Run the query
$found = $db->loadResult();
 
if ($found == 0) {
  return false;
} else {
  return true;
}

Because it's not working, I would like to put traces or echos to see if my variables content are rights.
If this can help anybody, I added some debugging informations in the wiki, based on your post, what I discovered and found in forums http://fabrikar.com/forums/index.php?wiki/debugging
Finally, I installed J!Dump, but I get a strange behaviour : $IDinput contains the string "{contacts___ContactsFormID}" and not it's supposed value.
If I cast $IDinput = (int) '{contacts___ContactsFormID}'; I get the value 0.
Thanks for help, i'm really stucked !
 
Another thing, with J!Dump if I use :
Code:
$query
    ->select('COUNT(*)')
    ->from('ContactsFormParams')
    ->where("ID = ". $IDinput);
I just see a structure without beeing able to see the SQL string

If I use the classic way, display is OK :
Code:
$query = "SELECT COUNT(*) FROM ContactsParams WHERE ID=" . $IDinput;

Is there an interest to use the first notation ?
 
The first notation allows you to use in theory different databases (e.g. postgre rather than mySQL). It also has the benefit of allowing you to build the query in stages.
I don't use jdump so can't comment on that - but if it uses print_r then $query is an object. you will need to dump the string , e.g dump

Code:
$db->setQuery($query);
dump($db->getQuery());

JDump may or may not output stuff is the request is format=raw as well. In using it you are adding another layer of things to go wrong/to check in my opinion. I would stick with simple print_r's and observe the ajax resposnse as Hugh says, there really will be output in there if the code is being triggered.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top