Welcome, Guest

Populate select-list from DB using user data
(1 viewing) (1) Guest
  • Page:
  • 1
  • 2

TOPIC: Populate select-list from DB using user data

Populate select-list from DB using user data 1 year, 10 months ago #13138

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;
?>
  • dack
  • OFFLINE
  • Fresh Boarder
  • Posts: 5
  • Karma: 0

Re:Populate select-list from DB using user data 1 year, 9 months ago #13242

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;
?>
  • Pete550
  • OFFLINE
  • Fresh Boarder
  • Posts: 11
  • Karma: 0

Re: Populate select-list from DB using user data 1 year, 6 months ago #14945

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

Re: Populate select-list from DB using user data 1 year, 6 months ago #14946

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
  • Pete550
  • OFFLINE
  • Fresh Boarder
  • Posts: 11
  • Karma: 0

Re: Populate select-list from DB using user data 1 year, 6 months ago #14948

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

Re: Populate select-list from DB using user data 1 year, 6 months ago #14952

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
  • Pete550
  • OFFLINE
  • Fresh Boarder
  • Posts: 11
  • Karma: 0
  • Page:
  • 1
  • 2
Moderators: TheMuffinMan, ForumSupport
Time to create page: 0.53 seconds

About

Crosstec GmbH & Co. KG

Bergisch-Gladbacher-Str. 829

51069 Cologne, Germany