• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: passing data from database to form fields

passing data from database to form fields 3 years 9 months ago #40325

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 213
  • Thank you received: 57
Just started trying to prefill fields in a form with a club members name and address when their membership number in the first field is found, I'vecome up with this attempt from Joomla docs
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
 
$query->select($db->quoteName(array('forename', 'surname')));
$query->from($db->quoteName('#_members'));
$query->where($db->quoteName($memnum) . ' = ' . $db->quote('member_id'));
 
return $db->loadResult();
$val['form']['Surname'] = $db->loadResult('surname');

Would this go in scripts before form generationor on form display plus I don't think I'm passing the surname and forename to the fields correctly. It's currently $val because it's in before generation scripts
Any advice help appreciated
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 3 years 9 months ago by iceferret.
The administrator has disabled public write access.

passing data from database to form fields 3 years 9 months ago #40326

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 213
  • Thank you received: 57
Cracked it after a bit of reading and some thinking. Once you get the external database connection the code is;
$db = JDatabaseDriver::getInstance( $option );
 
// Create a new query object.
$query = $db->getQuery(true);
 
// Select all records from the user profile table where the key is "$memnum.".
 
$query = $db
    ->getQuery(true)
      	->select('title')
    	->select('forename')
  	->select('Surname')
  	->select('housename_number')
     	->select('address_1')
    	->select('address_2')
        ->select('town')
        ->select('city')
	->select('county')
     	->select('Country')
    	->select('post_area_code')
        ->select('email')
        ->select('telephone')
    	->from($db->quoteName('rsf96104_rsf_members.members'))
    	->where($db->quoteName('member_id') . " = " . $db->quote($memnum));
 
$db->setQuery($query);
//load associative array
$row = $db->loadAssoc();
 
//prefill form fields
$val['Forename'] = $row['forename'];
$val['Surname'] = $row['Surname'];
$val['Telephone'] = $row['telephone'];
$val['Email'] = $row['email'];
$val['Housename or Number'] = $row['housename_number'];
$val['Address1'] = $row['address_1'];
$val['Address 2'] = $row['address_2'];
$val['Town'] = $row['town'];
$val['City'] = $row['city'];
$val['county'] = $row['county'];
$val['Postcode'] = $row['post_area_code'];
$val['Country'] = $row['country'];
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
Last Edit: 3 years 9 months ago by iceferret.
The administrator has disabled public write access.
The following user(s) said Thank You: gregs
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!