Jump to content

Help w/ drop-down list made more simple


albertg

Recommended Posts

I posted a topic a few days ago but no one responded. I have taken another stab at reducing the old code and adding a standard drop-down list but the list is only populating with 1 result and the one result doesn't submit the actual id to the submit function. Can someone please look at the original piece of code below and my attempt at the drop down list and offer any suggestions? Thanks...

 

 

Current multi-select code:

 

 

$iteration =0;

$skills = $skillChapter['Skill'];

foreach ($skills as $skill)

{

$skillid = $skill['id'];

$skillIds[] = array("skill".$skill['id'],$skill['title'],$skillChapter['SkillChapter']['title']);

echo "<div class=\"skillRow\">";

echo "<input type=\"checkbox\" name=\"data[Job][skill".$skillid."]\" value=\"1\" id=\"skill".$skillid."\"> ";

echo "<label for=\"skill".$skillid."\">{$skill['title']}</label>";

echo "</div>";

}

echo "</div>";

$iteration++;

echo "</div>";

 

 

 

 

My attempt to convert to a standard (single select) drop-down list. Below code is not working:

 

 

echo "<div class=\"floatClear\">";

echo $form->input( 'data[Job][skill".$skillid."]', array( 'label' => 'Select a Function', 'type'=>'select', 'options'=>

array("$skill".$skill['id'])));

echo "</div>";

Link to comment
https://forums.phpfreaks.com/topic/140471-help-w-drop-down-list-made-more-simple/
Share on other sites

Don't know exactly what you're doing but you have an opening <input> and no closing </input> in the foreach loop which could be why you are only getting 1 option. Also, if you use single quote on the echo calls you don't have to delimit the "s in the output, so:

 

echo "<input type=\"checkbox\" name=\"data[Job][skill".$skillid."]\" value=\"1\" id=\"skill".$skillid."\"> ";
echo "<label for=\"skill".$skillid."\">{$skill['title']}</label>";

would become:

echo '<input type="checkbox" name="data[Job][skill'.$skillid.']" value="1" id="skill'.$skillid.'\"> ';
echo '<label for="skill'.$skillid.'">{$skill['title']}</label>';

 

Which is a lot easier to read if you ask me. If echo() doesn't like single quotes you can use print('text'); instead.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.