bouyaka Posted April 14, 2012 Share Posted April 14, 2012 Hi all, I will wish to modify this code to get a choice of multiple selection, so I can select multiple category and not a single as it is currently. Here is the original code: {if $step==1} <div class="form_content"> <form name="newad" method="post" action="newad.php?step=1"> <label>{$lng.listings.category}<span class="mandatory"> *</span></label> <select id="category" name="category"> <option value="">{$lng.listings.category}</option> {foreach from=$categories item=v name=cat} {if $v.parent==1} <optgroup label="{$v.str}{$v.name}"> {else} <option value="{$v.id}" {if $tmp.category==$v.id}selected="selected"{/if}>{$v.str}{$v.name|escape:"html"}</option> {if ( $smarty.foreach.cat.index!=$categories|@count-1 && $v.parent_id!=$categories[$smarty.foreach.cat.iteration].parent_id) || ($smarty.foreach.cat.index==($categories|@count-1) && $v.parent_id!=0)} </optgroup> {/if} {/if} {/foreach} </select> {* ----------------------- levels drop down categories --------------------- *} {* <div> <select id="category1" name="category1" class="levels" onChange="chooseCateg(this.form, 1)"> <option value="">{$lng.listings.category}</option> {foreach from=$categories item=v name=cat} {if $v.parent_id==0} <option value="{$v.id}">{$v.name|escape:"html"}</option> {/if} {/foreach} </select> </div> <div style="display: none;" id="level2"> <select id="category2" name="category2" class="levels" onChange="chooseCateg(this.form, 2)"> </select> </div> <div style="display: none;" id="level3"> <select id="category3" name="category3" class="levels" onChange="chooseCateg(this.form, 3)"> </select> </div> <div style="display: none;" id="level4"> <select id="category4" name="category4" class="levels" onChange="chooseCateg(this.form, 4)"> </select> </div> <div style="display: none;" id="level5"> <select id="category5" name="category5" class="levels" onChange="chooseCateg(this.form, 5)"> </select> <input type="hidden" name="category" id="category" /> </div> *} <br/><br/> <div class="buttons"><strong><input type="submit" name="Choose_categ" id="Choose_categ" value="{$lng.listings.next_step}" /></strong></div> <div class="clearfix"></div> </form> </div> </div> {* end form_container *} {/if} {* end step1 *} Thank you for your help Link to comment https://forums.phpfreaks.com/topic/260943-multiple-selection/ Share on other sites More sharing options...
MMDE Posted April 14, 2012 Share Posted April 14, 2012 <?php if(isset($_POST['category'])){ foreach($_POST['category'] AS $category){ echo 'You selected category: '.$category.'.<br/>'; } } echo '<form action="" method="post">'; for($i=0; $i<10; $i++){ $rows[$i]['id'] = $i; $rows[$i]['category'] = 'category '.$i; } foreach($rows AS $row){ echo '<input type="checkbox" name="category[]" value="'.$row['id'].'" /> '.$row['category'].'<br/>'; } echo '<input "name="submit" type="submit" value="submit"/> </form>'; ?> You can create arrays of the checkbox names and identify them by their id! Or is it a drop down list you want, where you can select multiple values? Link to comment https://forums.phpfreaks.com/topic/260943-multiple-selection/#findComment-1337379 Share on other sites More sharing options...
Drummin Posted April 14, 2012 Share Posted April 14, 2012 <select id="category" name="category" multiple="multiple"> Link to comment https://forums.phpfreaks.com/topic/260943-multiple-selection/#findComment-1337380 Share on other sites More sharing options...
bouyaka Posted April 14, 2012 Author Share Posted April 14, 2012 thank you very much for your help. I tried both solution, unfortunately it does not work. here is the website: htt * :/ / www.mapmode. com / newad.php I will wish to select multiple categories, for example. the source file in the attachment here. Can you please help me. Thanks again 18069_.zip Link to comment https://forums.phpfreaks.com/topic/260943-multiple-selection/#findComment-1337388 Share on other sites More sharing options...
bouyaka Posted April 15, 2012 Author Share Posted April 15, 2012 hello, I tested the solution of Drummin, but other categories are no longer displayed. it remains fixed on a single category. Thank you for your help Link to comment https://forums.phpfreaks.com/topic/260943-multiple-selection/#findComment-1337488 Share on other sites More sharing options...
MMDE Posted April 15, 2012 Share Posted April 15, 2012 Maybe THIS may help you? Link to comment https://forums.phpfreaks.com/topic/260943-multiple-selection/#findComment-1337520 Share on other sites More sharing options...
Drummin Posted April 15, 2012 Share Posted April 15, 2012 I don't think I've ever seen such a crazy mix of html and php. The file is saved as html and so I don't see how php can work on this page. As for the php on the page I don't see any opening or closing <?php ?> tags so again I don't know how it could work. To be honest, I've never seen lines like $lng.listings.enter_ad_details ... which looks as though you are directly accessing DB tables and fields. Where are the mysql_query and where/how are all these variables being set? Link to comment https://forums.phpfreaks.com/topic/260943-multiple-selection/#findComment-1337600 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.