pikemsu28 Posted March 19, 2007 Share Posted March 19, 2007 i have a form that has four select dropdowns that i want to implode it into an array but ONLY if the dropdown has a value other than SELECT. I can get it to work as long as i populate all the menus but if i dont populate one 'SELECT' is posted to my array and i dont want that. Can someone please help?! point me in the right direction!!!! <form id="search" name="search" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <select class="small" name="dropdown[]"> <option selected="selected">Select</option> <option value="option">option</option> <option value="option1">option1</option> <option value="option2">option2</option> </select><br /> <select class="small" name="dropdown[]"> <option selected="selected">Select</option> <option value="option">option</option> <option value="option1">option1</option> <option value="option2">option2</option> </select><br /> <select class="small" name="dropdown[]"> <option selected="selected">Select</option> <option value="option">option</option> <option value="option1">option1</option> <option value="option2">option2</option> </select><br /> <select class="small" name="dropdown[]"> <option selected="selected">Select</option> <option value="option">option</option> <option value="option1">option1</option> <option value="option2">option2</option> </select><br /> <input id="search" name="search" type="submit" value="Search" /> </form> <?php if(isset($_POST['search'])) { if(isset($_POST['dropdown'])){$dropdown = implode(', ', (isset($_POST['dropdown']) ? ($_POST['dropdown']) : 'Select'));} echo $dropdown; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/43348-solved-concatenate-values-only-if-theyve-been-selected/ Share on other sites More sharing options...
pikemsu28 Posted March 20, 2007 Author Share Posted March 20, 2007 !BUMP! anyone? i can try to explain more if necessary. Quote Link to comment https://forums.phpfreaks.com/topic/43348-solved-concatenate-values-only-if-theyve-been-selected/#findComment-211098 Share on other sites More sharing options...
jitesh Posted March 20, 2007 Share Posted March 20, 2007 <form id="search" name="search" method="post" action="<?php $_SERVER['PHP_SELF']; ?>"> <select class="small" name="dropdown[]"> <option selected="selected">Select</option> <option value="option">option</option> <option value="option1">option1</option> <option value="option2">option2</option> </select><br /> <select class="small" name="dropdown[]"> <option selected="selected">Select</option> <option value="option">option</option> <option value="option1">option1</option> <option value="option2">option2</option> </select><br /> <select class="small" name="dropdown[]"> <option selected="selected">Select</option> <option value="option">option</option> <option value="option1">option1</option> <option value="option2">option2</option> </select><br /> <select class="small" name="dropdown[]"> <option selected="selected">Select</option> <option value="option">option</option> <option value="option1">option1</option> <option value="option2">option2</option> </select><br /> <input id="search" name="search" type="submit" value="Search" /> </form> <?php if(isset($_POST['search'])) { $imploded_str = ""; foreach($_POST['dropdown'] as $key => $value){ if($_POST['dropdown'][$key] != "Select"){ $imploded_str .= $value.","; } } $imploded_str = substr($imploded_str,0,strlen($imploded_str)-1); echo $imploded_str; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/43348-solved-concatenate-values-only-if-theyve-been-selected/#findComment-211117 Share on other sites More sharing options...
pikemsu28 Posted March 20, 2007 Author Share Posted March 20, 2007 Thanks!! i just could not get myself to think of how to do that. Quote Link to comment https://forums.phpfreaks.com/topic/43348-solved-concatenate-values-only-if-theyve-been-selected/#findComment-211122 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.