I used the following code in CF3/J1.5 to overwrite any previous records a user had submitted to the database. However, now I'm using CF4/J2.5 and the same code is not working or I am not setting it up correctly.
In CF3, this was placed in the "On Submit code - after sending email:" box. In CF4, I placed it in a "Custom Server Side Validation" action item first in the On Submit box but nothing seems to be happening with it. I have a DB Save action right after it. It saves the form to the database but does not overwrite, just adds more.
I'm guessing something changed in the new version of Joomla but I'm not a coder. Any help is appreciated.
<?php
$db =& JFactory::getDBO();
$user =& JFactory::getUser();
$query = sprintf('SELECT `cf_id` FROM %s WHERE `cf_user_id` = %d',
$db->nameQuote('#__chronoforms_data_test'),
$user->id
);
$db->setQuery($query);
$result = $db->loadResult();
JRequest::setVar('cf_id', $result ? $result : 0);
?>
In CF3, this was placed in the "On Submit code - after sending email:" box. In CF4, I placed it in a "Custom Server Side Validation" action item first in the On Submit box but nothing seems to be happening with it. I have a DB Save action right after it. It saves the form to the database but does not overwrite, just adds more.
I'm guessing something changed in the new version of Joomla but I'm not a coder. Any help is appreciated.
Hi,
Try to use a "custom code" action instead.
What's the name of the primary key column ? "cf_id" ? if yes then replace:
by:
Regards,
Max
Try to use a "custom code" action instead.
What's the name of the primary key column ? "cf_id" ? if yes then replace:
JRequest::setVar('cf_id', $result ? $result : 0);
by:
$form->data['cf_id'] = $result ? $result : null;
Regards,
Max
Hi Max,
Your solution worked except when I access the form from the New button on the Chronoconnectivity toolbar. When I access the form from the frontend link in Chronoforms it overwrites but not from CC. I would have thought that it would load the same cf_id into the form but when submitted through CC's link it adds a new record. Do I need to change a link to make it work through CC too? The cf_id is the primary key for the table
overwrites from: /index.php?option=com_chronoforms&chronoform=form-name
does not overwrite from: /component/chronoconnectivity/form_name
I also noticed that the Remove option in CC does not actually delete the selected record even though a system message pops up saying it was deleted.
thanks
Your solution worked except when I access the form from the New button on the Chronoconnectivity toolbar. When I access the form from the frontend link in Chronoforms it overwrites but not from CC. I would have thought that it would load the same cf_id into the form but when submitted through CC's link it adds a new record. Do I need to change a link to make it work through CC too? The cf_id is the primary key for the table
overwrites from: /index.php?option=com_chronoforms&chronoform=form-name
does not overwrite from: /component/chronoconnectivity/form_name
I also noticed that the Remove option in CC does not actually delete the selected record even though a system message pops up saying it was deleted.
thanks
This topic is locked and no more replies can be posted.