• 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: Get default field value in $formLayout

Get default field value in $formLayout 3 years 4 months ago #40779

  • patrick403
  • patrick403's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 42
  • Thank you received: 5
I have a form that I want to grab a default field value and use it in the Script called on form display $formLayout

Here is what I have so far:
$db = JFactory::getDbo();
$companyid = $_POST['form']['companyid'];
$q1 = $db->setQuery("SELECT designation FROM #__clients WHERE company_id = $companyid");
$designation = $q1->loadResult();
 
$formLayout = str_replace('{designation}', $designation, $formLayout);

Please help.
The administrator has disabled public write access.

Get default field value in $formLayout 3 years 4 months ago #40789

  • andreic
  • andreic's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 722
  • Thank you received: 59
Hello,

Can you please specify how the value of the field in question is set? Is this also set through a custom script?
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
The administrator has disabled public write access.

Get default field value in $formLayout 3 years 4 months ago #40790

  • patrick403
  • patrick403's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 42
  • Thank you received: 5
The value will be set through the url via an email link
The administrator has disabled public write access.

Get default field value in $formLayout 3 years 4 months ago #40797

  • patrick403
  • patrick403's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 42
  • Thank you received: 5
Any information on this?
The administrator has disabled public write access.

Get default field value in $formLayout 3 years 4 months ago #40798

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 214
  • Thank you received: 57
I have a similar situation to you in that I pass two form field values from form A via url into form B. In the latter i assigned those values to variables and connected to an external database. I am then able to get the data via a query where table1 = $var1 and table2 = $var2 then prefill
the form fields.
This is done in form2's php preprocessing scripting area not on display. There's a lot of code involved. I can post it here if you want to pick it over
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.

Get default field value in $formLayout 3 years 4 months ago #40799

  • patrick403
  • patrick403's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 42
  • Thank you received: 5
Please post that info. Thanks!
The administrator has disabled public write access.

Get default field value in $formLayout 3 years 4 months ago #40801

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 214
  • Thank you received: 57
Here you go, there's quite a bit of it but you'll see how i've done it.
//assign values passed in url from get mem-id form
$memnum=$val['membership_number'];
$surname = $val['Surname'];
 
//get members database connection
$option = array(); //prevent problems
 
 
 
$option['driver']   = 'mysql';            // Database driver name
$option['host']     = '*********';    // Database host name
$option['user']     = '************';       // User for database authentication
$option['password'] = '*********';   // Password for database authentication
$option['database'] = '***************';      // Database name
$option['prefix']   = '';             // Database prefix (may be empty)
if ($option->connect_error) {
   die("Connection failed: " . $option->connect_error);
}
 
//get Db driver instance
$db = JDatabaseDriver::getInstance( $option );
 
// Create a new query object.
$query = $db->getQuery(true)
      	->select('m.title')
  		->select('m.member_id')
  		->select('m.renewal_date')
  		->select('m.category')
    	->select('m.forename')
  		->select('m.Surname')
  		->select('m.birthday')
 		->select('m.age')
  		->select('m.housename_number')
     	->select('m.address_1')
    	->select('m.address_2')
        ->select('m.town')
        ->select('m.city')
		->select('m.county')
     	->select('m.Country')
    	->select('m.post_area_code')
        ->select('m.email')
        ->select('m.telephone')
         ->select('m.avg_cycle_number')
         ->select('h.householdmem_id1')
         ->select('h.h_name1')
         ->select('h.householdmem_id2')
         ->select('h.h_name2')
         ->select('h.householdmem_id3')
         ->select('h.h_name3')
         ->select('h.householdmem_id4')
         ->select('h.h_name4')    
 
    	->from($db->quoteName('rsf96104_rsf_members.members' , 'm'))
        ->Join('LEFT',$db->quoteName('Household' , 'h') . 'ON' . $db->quoteName('h.member_id') . '=' . $db->quoteName('m.member_id'))
->where($db->quoteName('m.member_id') . " = " . $db->quote($memnum) . " and " . $db->quoteName('m.Surname') . " = " . $db->quote($surname));
 
 
 
// Reset the query using the newly populated query object.
$db->setQuery($query);
 
// load row from database as associated array
$row = $db->loadAssoc();
 
//compare members entry to database entries, if not the same redirect and stop
if($memnum != $row['member_id'] && $surname != $row['Surname']) {
  header('Location: https://your redirect url here');
 //stop code below from being executed
  exit();
}
 
//else {
 
//assign array values to form fields  
$val['expires'] = $row['renewal_date'];
$val['category'] = $row['category']; 
$val['Title'] = $row['title']; 
$val['Forename'] = $row['forename'];
$val['birthday'] = $row['birthday'];
$val['Telephone'] = $row['telephone'];
$val['Email'] = $row['email'];
$val['housename or number'] = $row['housename_number'];
$val['address1'] = $row['address_1'];
$val['address2'] = $row['address_2'];
$val['town'] = $row['town'];
$val['city'] = $row['city'];
 
if($row['Country'] == 'United Kingdom') {
$val['uk_county'] = $row['county'];
$val['county'] = "";
}
elseif($row['Country'] !== 'United Kingdom')  {
$val['county'] = $row['county'];
$val['uk_county'] = "";  
}
 
$val['postcode'] = $row['post_area_code'];
$val['country'] = $row['Country'];
$val['participation'] = $row['avg_cycle_number']; 
$val['household_1'] = $row['h_name1'];
$val['housemem_id1'] = $row['householdmem_id1'];
$val['household_2'] = $row['h_name2'];
$val['housemem_id2'] = $row['householdmem_id2'];
$val['household_3'] = $row['h_name3'];
$val['housemem_id3'] = $row['householdmem_id3'];
$val['household_4'] = $row['h_name4'];
$val['housemem_id4'] = $row['householdmem_id4'];
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.
The following user(s) said Thank You: patrick403

Get default field value in $formLayout 3 years 4 months ago #40804

  • patrick403
  • patrick403's Avatar
  • OFFLINE
  • Senior Boarder
  • Posts: 42
  • Thank you received: 5
The following worked for me:
$db = JFactory::getDbo();
$companyid = $val['companyid']; // val is the form field passed through the URL
$q1 = $db->setQuery("SELECT designation FROM #__clients WHERE company_id = $companyid");
$designation = $q1->loadResult();
 
$formLayout = str_replace('{designation}', $designation, $formLayout);
Last Edit: 3 years 4 months ago by patrick403.
The administrator has disabled public write access.

Get default field value in $formLayout 3 years 4 months ago #40808

  • iceferret
  • iceferret's Avatar
  • OFFLINE
  • Gold Boarder
  • Posts: 214
  • Thank you received: 57
Glad to hear you got it working B)
If you can keep your head when all about you are losing theirs, then you obviously don't understand the situation!
The administrator has disabled public write access.
  • 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!