PHP in Form email plugin

koekkoek

New Member
Hello,

We have a form containing a dropdown with a departments list.
The dropdown only contain dept id and dept name

On form submit, we have a mail plugin using php to get the dept email address from a table (using the id as key).

This is the php code : -----------------------------------------
// Get a Joomla DB and Query
$db = JFactory::getDbo();
$query = $db->getQuery(true);

//Get and cast the combo's id value
$tid = (int) '{_vitto_contacts___destinataire_raw}';

//Get the email value
$query->select('id','email');
$query->from('_vitto_contacts'); // This is a fabrik table...
$query->where('id=' . $tid );
$db->setQuery($query);
$dest = $db->loadObject();

//Return the value to plugin
return $dest->email;
-------------------------------------------------------------------

But nothing happens, the mail address remains empty !

Please help, this is an emergency.

Best regards
 
For debugging try
...
$dest = $db->loadObject();
echo $query;
var_dump($tid,$dest);exit;
...

What do you get?
 
Iirc, the J! query builder select() accepts either a single string arg of comma separated fields ...

->select('foo, bar')

... or a single array arg of fields ...

->select(array('foo', 'bar'))

... or ...

->select($myDb->quoteName('foo', 'bar'))

... but not multiple single field args

->select('foo', 'bar')

PS ... in eval'ed code like this, it's best to steer clear of common variable names like $db and $query, as you can wind up clobbering ones with the same name in the code calling yours. You'll find a lot of older examples in the forums use them, but best to use something like $myDb and $myQuery.

-- hugh
 
Hi,

Changing generic names $db and $query to specific names did the job.
Are the used as globals ?

Tank you and best regards
 
Not globals, but your code is being eval'ed, which means it is in the same scope as the code that evals it.

Hugh


Sent from my Nexus 7 using Tapatalk
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top