Canman2005 Posted August 26, 2009 Share Posted August 26, 2009 Hi all I have a List/Menu which looks lik <select name="users1[]" id="users1[]" multiple="multiple"> <option value="Dolor">Dolor</option> <option value="Donec">Donec</option> <option value="Integer">Integer</option> <option value="Lacus">Lacus</option> <option value="Leo">Leo</option </select> Is it possible to use foreach($_POST['users1'] as $d) on all items in the List/Menu, despite if they have been selected or not? thanks in advance ed Link to comment https://forums.phpfreaks.com/topic/171874-solved-using-foreach-on-deselected-items/ Share on other sites More sharing options...
redarrow Posted August 26, 2009 Share Posted August 26, 2009 only if all the value name are in a array ok. i think you have set the form correctly have you tested it yet? Link to comment https://forums.phpfreaks.com/topic/171874-solved-using-foreach-on-deselected-items/#findComment-906262 Share on other sites More sharing options...
Canman2005 Posted August 26, 2009 Author Share Posted August 26, 2009 If I try and submit the form without any being selected, I get Warning: Invalid argument supplied for foreach() whereas I want it to ignore the fact none are selected and just carry through all the values from the List/Menu even the ones which are not selected. Link to comment https://forums.phpfreaks.com/topic/171874-solved-using-foreach-on-deselected-items/#findComment-906266 Share on other sites More sharing options...
redarrow Posted August 26, 2009 Share Posted August 26, 2009 firstly you mean this i guess then what please? <select name="users1[]" id="users1[]" multiple="multiple"> <?php $array=array("Dolor","Donec","Integer","Lacus","Leo"); foreach($array as $result){ echo"<option value='$result'>$result</option>"; } ?> </select> Link to comment https://forums.phpfreaks.com/topic/171874-solved-using-foreach-on-deselected-items/#findComment-906270 Share on other sites More sharing options...
Canman2005 Posted August 26, 2009 Author Share Posted August 26, 2009 the problem is im unable to do $array=array("Dolor","Donec","Integer","Lacus","Leo"); simply because the values in "users1[]" are dynamically added from another List/Menu, its basically javascript passing over the values from one list to another. Link to comment https://forums.phpfreaks.com/topic/171874-solved-using-foreach-on-deselected-items/#findComment-906273 Share on other sites More sharing options...
redarrow Posted August 26, 2009 Share Posted August 26, 2009 try this a shot in the dark sorry. Please hold down ctl button to selct more then one option please. <br/><br/> <select name="users1[]" id="users1[]" multiple="multiple"> <?php $array=array("Dolor","Donec","Integer","Lacus","Leo"); foreach($array as $result){ echo"<option value='$result'>$result <br></option>"; } ?> </select> <br/><br/> <input type="submit" name="submit" value="SEND!"> <?php if(isset($_POST['submit'])){ foreach($users1 as $final_result){ echo "You Selected: $final_result"; } } ?> Link to comment https://forums.phpfreaks.com/topic/171874-solved-using-foreach-on-deselected-items/#findComment-906275 Share on other sites More sharing options...
Canman2005 Posted August 26, 2009 Author Share Posted August 26, 2009 but I don't know what values are being passed over from one List to another, therefore doing $array=array("Dolor","Donec","Integer","Lacus","Leo"); would not be possible unless I knew what values the user was going to pass from one to another Link to comment https://forums.phpfreaks.com/topic/171874-solved-using-foreach-on-deselected-items/#findComment-906279 Share on other sites More sharing options...
Canman2005 Posted August 26, 2009 Author Share Posted August 26, 2009 It's ok, im going to use a javascript to select all the items in the List/Menu when the submit button is clicked Link to comment https://forums.phpfreaks.com/topic/171874-solved-using-foreach-on-deselected-items/#findComment-906313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.