I used this code in a php plugin of the assessment form to create two records in two separate tables (Client and address book) and catch id of the client and save it in the assessment table.
Code is working but because the process script of php plugin set as "onBeforeProcess" and form has a confirmation plugin to validate data, it creates two duplicate records in each table, because this code runs two times.
I tried to change the process script of php plugin to other options but it didn't work.
I think I need to condition to run the code only once time after validation data but I don't know how!
Code is working but because the process script of php plugin set as "onBeforeProcess" and form has a confirmation plugin to validate data, it creates two duplicate records in each table, because this code runs two times.
I tried to change the process script of php plugin to other options but it didn't work.
I think I need to condition to run the code only once time after validation data but I don't know how!
Code:
// create a record in the Client table
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->insert('app_clients')
->set('date_time = ' . $myDb->quote('{app_assessment___date_time}'))
->set('type = ' . $myDb->quote('lead'))
->set('created_by = ' . $myDb->quote('{app_assessment___created_by}'))
->set('office_id = ' . $myDb->quote('{app_assessment___preferred_office}'))
->set('status = ' . $myDb->quote('open'))
->set('name = ' . $myDb->quote('{app_assessment___name}'));
$myDb->setQuery($myQuery);
$myDb->execute();
// Catch client id from client table
$formModel->updateFormData('app_assessment___client_id', $myId);
// create a record in the address table
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery->insert('app_address_book')
->set('date_time = ' . $myDb->quote('{app_assessment___date_time}'))
->set('client_id = ' . $myDb->quote($myId))
->set('email = ' . $myDb->quote('{app_assessment___email}'))
->set('office_id = ' . $myDb->quote('{app_assessment___preferred_office}'))
->set('mobile = ' . $myDb->quote('{app_assessment___mobile}'))
->set('country = ' . $myDb->quote('{app_assessment___country_of_residence}'))
->set('name = ' . $myDb->quote('{app_assessment___name}'));
$myDb->setQuery($myQuery);
$myDb->execute();