SOLVED - Setting dropdown to a default before loading form

nclaypool

Member
I have a system where a user sets a personal default for a couple of fields on another form. Using the PHP plugin on the actual form I was at one time able to set the default selections on two different dropdown menus, these menus are database joins pulling from a preconfigured list of vendors. I'm not precisely certain when it stopped as not a ton of people use it and nobody said anything until I tried to use it and found it was no longer working. I know the overall code is good as I have a text field that gets auto populated from the user's default record just fine.

Here is my code
PHP:
// Are Vendor, Ship To, and Charge To Already Set
$cur_vendor = $formModel->getElementData('purchase_orders___vendor', true);
$cur_shipto = $formModel->getElementData('purchase_orders___ship_to', true);
$cur_charge = $formModel->getElementData('purchase_orders___charged_to', true);

// Get the currently logged in user ID
$user_id = JFactory::getUser();
$user_id = $user_id->get('id');

// Retrieve values of database
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
  ->select(array('default_vendor', 'default_ship_to', 'default_charged_to'))
  ->from('user_defaults')
  ->where('user = ' . $user_id);
 
$db->setQuery($query);
$defaults = $db->loadObject();

// Assign variables for DB values
$vendor = $defaults->default_vendor;
$ship_to = $defaults->default_ship_to;
$charge_to = $defaults->default_charged_to;

// Set fields on form with this values
if ($cur_vendor == 0)
{ $formModel->data['purchase_orders___vendor']=$vendor; }

if ($cur_shipto == 0)
{ $formModel->data['purchase_orders___ship_to']=$ship_to; }

if ($cur_charge == '')
{ $formModel->data['purchase_orders___charged_to']=$charge_to; }

In an effort to troubleshoot I made few tweaks. Previously the code would check to see if a selection had already made, it would no it wasn't if the value of the field was null as no value was assigned to the Please select option. I then assigned a value of zero to that option and modified the code, no change.

Am I maybe using methods that are no longer supported?
 
PHP:
// Set fields on form with this values
if ($cur_vendor == 0)
{ $formModel->data['purchase_orders___vendor_raw']=$vendor; }

if ($cur_shipto == 0)
{ $formModel->data['purchase_orders___ship_to_raw']=$ship_to; }

if ($cur_charge == '')
{ $formModel->data['purchase_orders___charged_to_raw']=$charge_to; }
 
PHP:
// Set fields on form with this values
if ($cur_vendor == 0)
{ $formModel->data['purchase_orders___vendor_raw']=$vendor; }

if ($cur_shipto == 0)
{ $formModel->data['purchase_orders___ship_to_raw']=$ship_to; }

if ($cur_charge == '')
{ $formModel->data['purchase_orders___charged_to_raw']=$charge_to; }

That did it! Thank you very much.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top