albertg Posted January 12, 2009 Share Posted January 12, 2009 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 More sharing options...
sKunKbad Posted January 12, 2009 Share Posted January 12, 2009 So, you must be using some sort of form creation class eh? You should supply more code, and then you have a better chance of having somebody help you. Link to comment https://forums.phpfreaks.com/topic/140471-help-w-drop-down-list-made-more-simple/#findComment-735619 Share on other sites More sharing options...
Yesideez Posted January 13, 2009 Share Posted January 13, 2009 Instead of using foreach() I'd set up an actual for() loop - you're setting the value of each option to 1 hardcoded in. I'd also say using the bbcode CODE tags would make the code you're posting a LOT easier to read. Link to comment https://forums.phpfreaks.com/topic/140471-help-w-drop-down-list-made-more-simple/#findComment-736062 Share on other sites More sharing options...
Catfish Posted January 17, 2009 Share Posted January 17, 2009 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. Link to comment https://forums.phpfreaks.com/topic/140471-help-w-drop-down-list-made-more-simple/#findComment-738845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.