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'], 0, false, 0, 1 );

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'], 0, false, 0, 1 );

$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.