bespokeappstt
Hubstaff freelancer
I have a list called 'Equipment' and two elements called SerialNumber and Availability. Availability has the values 'Yes' or 'No' using a dropdown. SerialNumber is self-explanatory. Now there is another list called 'Rental' and it also has an element called SerialNumber that is a 'databasejoin' on the 'Equipment' list, SerialNumber. I want to be able to create entries in the 'Rental' list and every time a 'SerialNumber' is chosen the 'Availability' is toggled to 'No' in the 'Equipment' list for the row of data with that SerialNumber. SerialNumbers are unique and can only be listed in the 'Equipment' list once. If I hard code the 'SerialNumber', the php form plugin code works. So the issue I am having right now is grabbing the value of 'SerialNumber' from the rad_rentals___serial element. The documentation says for a databasejoin dropdown, the values are in an array and it then goes on to show how to get the first value. But it doesn't show how to get the value the user actually selects. How do I get the value the user actually selects. Here is the code
Code:
//Hard coded value works
//$serialNumber = '564789985155';
$serialNumber = $formModel->getElementData('rad_rentals___serial', true);
$serialNumber = is_array($serialNumber) ? $serialNumber[0] : $serialNumber;
// Get the db and the query
$db = JFactory::getDbo();
$query = $db->getQuery(true);
//Field to update
$field = 'available = 0';
//Reference column
$conditions = 'serial_number' . '= '. $serialNumber;
$query->update($db->quoteName('rad_serialassets'))->set($field)->where($conditions);
$db->setQuery($query);
$result = $db->execute();
return $result;