Populate select-list from DB using user data

  • dack
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 5
  • Thank you received: 0

dack created the topic: Populate select-list from DB using user data

Hi,

I'm trying to populate a select-list filtered by data entered by the user. The error i'm gettijg in the code below is 'Call to undefined function getElementById'.

I've tried using ff_getElementByName but same error.

Any ideas anyone please?
<?php
/*
This php code is executed while the page is created.
It queries the userlist by sql and creates options for the select list.
*/
$users = ff_select("select name, username from #__users");
$options = '';
if ($users)
foreach ($users as $user)
if ($user->name == document.getElementById('User').value)
$options .= "0;$user->name;$user->username\n";
return $options;
?>
#13138
  • Posts: 10
  • Thank you received: 0

Pete550 replied the topic: Re:Populate select-list from DB using user data

in Beginn Formular:
global $userlist;
$this->execPieceByName('ff_InitLib');

$strquery = "SELECT `name`, `username ` FROM #__users ".    
            "ORDER BY name; ";

$rows = ff_select( $strquery );

$userlist="0;Username;0\n";
if (Count($rows))
{
   foreach($rows as $record)
   {
      $userlist.="0;$record->name; $record->username\n";
   }
}


in your select List under options:
<?php
  global $userlist;
  return $userlist;
?>
#13242
  • facommunications.com
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 0

facommunications.com replied the topic: Re: Populate select-list from DB using user data

Hi Peter,

Could you please help me here.

I'm trying to populate a select list with content that I retrieve from database #__categories.
I have this piece of code that is in "Before Form" option of my form.
// load the standard form creation utilities
$this->execPieceByName('ff_InitLib');

//set globals
global $record;

//set value of id
$rid = ff_getParam('ff_param_rid');

//load existing data
global $record;

//query db
$rows = ff_select("select `title` from `#__categories` where published=1");

$categorie="1;Veuillez choisir un;\n";
   
   if (Count($rows))
{
   foreach($rows as $record)
   {
      $categorie.="0;$record->title; $record->title\n";
   }
}

In my "Select List" Categorie, in "Advanced" tab then "Initscript" I selected "Custom" and have put this code
<?php
  global $categorie;
  return $categorie;
?>

Whoever in my form my "Categorie" select list is empty. Do you know what is not working in what I'm doing? I'm not even sure what I'm doing is the right way.

Thank you very much in advance for your help.

Helio
#14945
  • Posts: 10
  • Thank you received: 0

Pete550 replied the topic: Re: Populate select-list from DB using user data

Hi Helio

make a new select list and under options are something like:
1;Select Color;''
0;Red;red
0;Green;green
0;Blue;blue

delete this complete an copy in:
<?php
  global $categorie;
  return $categorie;
?>

thats all.



You build your options here in Before Form:
$categorie.="0;$record->title; $record->title\n";
example $categorie result:
0;Helio;Helio
0;admin;admin

thats the same like
0;Red;red
0;Green;green


greetings
#14946
  • facommunications.com
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 9
  • Thank you received: 0

facommunications.com replied the topic: Re: Populate select-list from DB using user data

Hi Peter,

Thank you for your fast reply.

This is what I did, I created a select list element and deleted default content:
0;Title 1;value1
0;Title 2;value2
0;Title 3;value3


But in select list elements I don't have "Options", what I have is, under "Advanced" tab:
Element Options where I have:
Hide label
Mailback
Logging
Order Number
Tab index
Turn off
Title position

Then I have Initscript where I have:
Type: None Library Custom
When I select "Custom" I get a field where I can put content.
I also have two options: Form Entry and Page Entry
I can select either Form Entry or Page Entry, none or both.
In the field I've put this content:
<?php
  global $categorie;
  return $categorie;
?>
And finally I have Actionscript where I also have
Type: None Library Custom

So should the code
<?php
  global $categorie;
  return $categorie;
?>
be in Initscript as I did or should it be somewhere else?

Thank you
#14948
  • Posts: 10
  • Thank you received: 0

Pete550 replied the topic: Re: Populate select-list from DB using user data

do you work with easy mode?
the instructions are for classic mode

i have to take a look at easy mode.
never worked with easy mode before

but php code dont work in javascript.
Actionscript, Initscript are for JS
#14952
Moderators: ForumSupporttomeperica
Time to create page: 0.063 seconds

New Icon Packs Category!

Crosstec is now offering icon packs.

If you are a paying subscriber, icon packs are automatically added to your account.

Check out our icon packs page!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Summer Sale!

50% discount on all of our extension subscription plans, templates and icon packs!

Get Your Subscription Here

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

All Extensions Subscription

Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for just 49! (Summer Sale)

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Live Support Chat Opened!

Join our Discord chat here to receive live support and talk directly to the team!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here