• 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: Pre-selecting fields in a dropdown list using PHP

Pre-selecting fields in a dropdown list using PHP 11 years 2 weeks ago #27312

  • post552
  • post552's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 1
Hi!

I'd like to be able to pre-select entries in a dropdown list based on the site URL using PHP.

Using another forms component, I was able to do this by using this code:

PHP code when the form loads
<?php
$topics = array ("cherry", "apple", "banana");
$topic = "'';
$counter = 0;
$urli = $_SERVER['REQUEST_URI'];
 
foreach ($topics AS $checkit)
   {
$counter = 0;
  $counter = substr_count($urli,$checkit);
if ($counter != 0) {$topic = $checkit;}
   }?>

PHP code embedded in the dropdown field
<option value="Apples"<?php if ($topic == "apple") {echo ' selected';}?>>One apple a day ...</option>
<option value="Cherries"<?php if ($topic == "cherry") {echo ' selected';}?>>Cherries are red</option>
<option value="Bananas"<?php if ($topic == "banana") {echo ' selected';}?>>Bananas are the best</option>
<option value="othertopic">different topic</option>

Website visitors opening www.abc.com/applepies.html would be shown the form with Apples preselected. Visitors opening www.abc.com/importedbananas.html would be shown the same form with Bananas preselected.

Now I'm trying to figure out how to do the same with RSForm. I would include code portion #1 when the form loads - so far, so easy. But how do I include it in the dropdown field? I know I could include an entire chunk of PHP using //<code>, but this doesn't really work in this case. And - maybe there is an ever simpler way to do this with RSForm?

Any input is greatly appreaciated!
The administrator has disabled public write access.

Pre-selecting fields in a dropdown list using PHP 11 years 2 weeks ago #27321

  • alexp
  • alexp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 2253
  • Thank you received: 180
RSForm!Pro does have a value|label syntax for selectable fields. More details on dropdown configuration here:

http://www.rsjoomla.com/support/documentation/view-article/827-dropdown.html

Given the fact the field's Items section can execute PHP code, you would simply need to return the items separated by new lines. Example:

value 1|Label 1
value 2|Label 2
value 3|Label 3

A small example is available here:

http://www.rsjoomla.com/support/documentation/view-article/94-auto-populate-a-list-from-a-table.html
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!