• 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: Populate a field based on another fields value?

Populate a field based on another fields value? 10 years 3 months ago #30272

  • djaber2000
  • djaber2000's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 33
  • Thank you received: 3
I am trying to populate text field(s) based on another fields value (or a fields default value if it can not grab the typed in text), by using a sql query (following this example). I am querying an external mapped table, so a hard coded conditional situation will not work here.

//<code>
$db = JFactory::getDbo();
$db->setQuery("SELECT `column_name` FROM `#__table_name` WHERE `column_name`='value' LIMIT 1");
return $db->loadResult();
//</code>

But instead of 'value' I would like to use the placeholder of a field in the current form {field_name:value} to have the query check against, like so, but it does not work (even when I set the 'field_name' to have a default value:
//<code>
$db = JFactory::getDbo();
$db->setQuery("SELECT `column_name` FROM `#__table_name` WHERE `column_name`='{field_name:value}' LIMIT 1");
return $db->loadResult();
//</code>


Is this possible? If not in the fields Default area, how about in the $formLayout area? I am trying to find an example of this, but keep coming up short.

Thank you for any suggestions.
Last Edit: 10 years 3 months ago by djaber2000.
The administrator has disabled public write access.

Populate a field based on another fields value? 10 years 2 months ago #30458

  • Vince66
  • Vince66's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
Is there solution for this ... 2 pages, on first form with fields and on second also form fields but with already selected fields from first page?

Thank you for any help !
The administrator has disabled public write access.

Populate a field based on another fields value? 10 years 2 months ago #30485

  • silviup
  • silviup's Avatar
  • OFFLINE
  • Moderator
  • Posts: 309
  • Thank you received: 49
If you intend to connect to an external database, you will need to adapt the connection part of the script by specifying the hostname.

Also, using '{field_name:value}' in the script will not be helpful, as placeholders do not get replaced within PHP scripts.
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
Last Edit: 10 years 2 months ago by silviup.
The administrator has disabled public write access.

Populate a field based on another fields value? 10 years 2 months ago #30486

  • silviup
  • silviup's Avatar
  • OFFLINE
  • Moderator
  • Posts: 309
  • Thank you received: 49
I'm back with more details regarding the external database connection:

You will need to use the JDatabaseDriver::getInstance() method and pass the following information to it:

Database driver name - example: 'mysql' (or whatever is in use by the database that you are connecting to)

Database host name - example: 'db.myhost.com'

User for database authentication - example: 'username'

Password for database authentication - example: 'password'

Database name - example: 'database'

Database prefix (may be empty) - example: 'prefix_'

Given the examples above, the code used to connect to that external database should look something like this:
$db = JDatabaseDriver::getInstance('mysql', 'db.myhost.com', 'username', 'password', 'database', 'prefix_');

More information on this topic can be found in the Joomla! documentation:

docs.joomla.org/Connecting_to_an_external_database
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.
  • 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!