[solved]OnBeforeProcess - stop creating record in table

Status
Not open for further replies.

shortbow

New Member
Hi,
I'm guessing this is one of those questions the answer is very simple, but I've already lost a lot of hours over this, and am ready to start trying workarounds I really would prefer not to ...

So, I'me putting some php code in a form plug-ins in the "hook" OnBeforeProcess.
I had no problem with the this first part
//------------------------------------------------------------------------------------------------
$foo = $formModel->getElementData('jo_marc___equip_type', false);
$type_equip = is_array($foo) ? $foo[0] : $foo;

$foo = $formModel->getElementData('jo_marc___client_id',false);
$client = is_array($foo) ? $foo[0] : $foo;

$label = $type_equip. "-". $client;
$formModel->updateFormData('jo_marc___Label', $label , true);

When I submited the form it created my table record, with the value of the updated element no problem.

when I added this part(bellow), after submit, although it does not report any error, it also don't insert any new record in the database table... any ideas?
//------------------------------------------------------------------------------------------------
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
->select(array('name', 'address', 'location', 'cell', 'comment'))
->from('jo_clients')
->where('cli_id = ' . $client);

$myDb->setQuery($myQuery);
$row = $myDb->LoadObject();

//$formModel->updateFormData('jo_marc___client_name', $row->name,true);
//$formModel->updateFormData('jo_marc___client_address', $row->address, true);
//$formModel->updateFormData('jo_marc___client_location', $row->location, true);
//$formModel->updateFormData('jo_marc___client_cell',$row->cell, true);
//$formModel->updateFormData('jo_marc___client_comment', $row->comment, true);

thanks!
 
I think it's loadObject;
You can set Joomla's error reporting to max and put an exit; at the end of your code to see an error message.
You can use var_dump($xy); exit; to debug variables...
 
Unless you changed the $foo names, you never assigned $client a value.

Sent from my HTC6545LVW using Tapatalk
 
Hi,

I've been doing some tests, and I'm thinking I'm missing something obvious, I just dont know what is it.

In desperation I've tried:
$label="test";
$formModel->updateFormData('jo_marc___Label', $label , true);

and it worked without a problem.
then I tried:

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
->select(array('name', 'address', 'location', 'cell', 'comment'))
->from('jo_clients')
->where('cli_id = ' . $client);

$myDb->setQuery($myQuery);

$label="test";
$formModel->updateFormData('jo_marc___Label', $label , true);

Also without a problem.
Then I tried:

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
->select(array('name', 'address', 'location', 'cell', 'comment'))
->from('jo_clients')
->where('cli_id = 1' );

$myDb->setQuery($myQuery);
$row = $myDb->loadObject();

$label="test";
$formModel->updateFormData('jo_marc___Label', $label , true);

And it stoped creating an event in the database, no error reported...
I'm thinking I can't make this kind of call in this form event " OnBeforeProcess"...
Or there is some option in the Form setup I'm missing?
Maybe because the Form is connected to joo_marc when try to query the table jo_clients, the form looses connection to joo_marc ?
 
Hi,

I've been doing some tests, and I'm thinking I'm missing something obvious, I just dont know what is it.

In desperation I've tried:
$label="test";
$formModel->updateFormData('jo_marc___Label', $label , true);

and it worked without a problem.
then I tried:

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
->select(array('name', 'address', 'location', 'cell', 'comment'))
->from('jo_clients')
->where('cli_id = ' . $client);

$myDb->setQuery($myQuery);

$label="test";
$formModel->updateFormData('jo_marc___Label', $label , true);

Also without a problem.
Then I tried:

$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);

$myQuery
->select(array('name', 'address', 'location', 'cell', 'comment'))
->from('jo_clients')
->where('cli_id = 1' );

$myDb->setQuery($myQuery);
$row = $myDb->loadObject();

$label="test";
$formModel->updateFormData('jo_marc___Label', $label , true);

And it stoped creating an event in the database, no error reported...
I'm thinking I can't make this kind of call in this form event " OnBeforeProcess"...
Or there is some option in the Form setup I'm missing?
Maybe because the Form is connected to joo_marc when try to query the table jo_clients, the form looses connection to joo_marc ?
On the line before the loadObject, do..

var_dump((string) $myQuery); exit;

That should dump out the query. Copy it and try running it in phpMyAdmin.

BTW, are your tables on the default Joomla database connection?

Hugh

Sent from my HTC6545LVW using Tapatalk
 
On the line before the loadObject, do..

var_dump((string) $myQuery); exit;

That should dump out the query. Copy it and try running it in phpMyAdmin.

BTW, are your tables on the default Joomla database connection?

Hugh

Sent from my HTC6545LVW using Tapatalk

The "var_dump((string) $myQuery); exit;" don't show anything.

No, I've created a diferent database (and connection) for my site data.
 
I've found what was the problem, I have 2 DB connections, my querys were failling because I was not making the connection to the right database.

After setting the right connection ( $myDb = FabrikWorker::getDbo(false, 2); ) all went without a problem.

Thanks!
 
yes, it was that question you made that started me thinking about it! :D

Once again Thanks to you and Troester
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top