1
ralf57
Building dropdowns...
  • 2005/2/11 8:11

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Hi all,
i have this code:
$storyarray NewsStory :: getAllPublished($xoopsModuleConfig['storycountadmin'], 0false0);

echo 
"<select name="articles" style="width:300px">";
    echo 
"<option value="" selected>Select story</option>";
    foreach( 
$storyarray as $eachstory ) {    
    echo 
"<option value="" . XOOPS_URL . "/modules/news/article.php?storyid=". $eachstory -> storyid() ." ">" $eachstory -> title() . "</option>";
        }
    echo 
"</select>";


which generates a dropdown with the last 10 published news.
The code works fine but i'm wondering how can write it in
a more elegant way using the xoops's built-in form elements.
Thanks in advance,ralf.

2
Mithrandir
Re: Building dropdowns...

include_once XOOPS_ROOT_PATH."/class/xoopsformloader.php";

$storyarray NewsStory :: getAllPublished($xoopsModuleConfig['storycountadmin'], 0false0);

$form = new XoopsForm("title""form name""actionfile.php");
$article_select = new XoopsFormSelect("caption""articles");
$article_select->addOption("""Select Story");
foreach (
array_keys($storyarray) as $i) {
    
$article_select->addOption(XOOPS_URL "/modules/news/article.php?storyid="$storyarray[$i]-> storyid(), $storyarray[$i]->title() );
}
$form->addElement($article_select);
$form->display(); //or $form->assign($xoopsTpl); if you want to use a template

3
ralf57
Re: Building dropdowns...
  • 2005/2/11 12:34

  • ralf57

  • Quite a regular

  • Posts: 231

  • Since: 2003/2/3 1


Thank you mith,
it works perfectly.
BTW,i'm collecting many tips from you in these forums;
perhaps one day i'll release a quick reference for modules developers.

Login

Who's Online

235 user(s) are online (157 user(s) are browsing Support Forums)


Members: 0


Guests: 235


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits