bschultz Posted September 20, 2012 Share Posted September 20, 2012 Is there a function to determine which $_POST variable = foo? I have a form with 20 elements...and need to know which one equals another variable that's set in the script...and don't want to write a 400 layer deep if statement. Thanks! Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 20, 2012 Share Posted September 20, 2012 $key = array_search('foo', $_POST); Quote Link to comment Share on other sites More sharing options...
bschultz Posted September 20, 2012 Author Share Posted September 20, 2012 That's what I'm looking for...thanks for the quick reply! Quote Link to comment Share on other sites More sharing options...
bschultz Posted September 20, 2012 Author Share Posted September 20, 2012 Step two of this project requires building the html form (dynamically) based on what the user has already selected. I thought there was a way to do this in php, but my searching on Google lead me to jquery and ajax (of which I know neither of them!). I want to have an array of options for a form select box. Once the user selects the first select box, a second select box shows up with every option EXCEPT WHAT WAS SELECTED IN THE FIRST BOX...and repeats it's self until the array is empty (every array item has been selected). Can this be done in PHP? This is what I have so far...which does work...but it's only 2 select boxes...of 20! I can only hope it can done simpler than this: <?php $fields = array('Number', 'Name', 'Picture', 'Position', 'Height', 'Weight', 'Year', 'Home', 'Last School'); $submitted = array("$_POST[column1]", "$_POST[column2]", "$_POST[column3]", "$_POST[column4]", "$_POST[column5]", "$_POST[column6]", "$_POST[column7]", "$_POST[column8]", "$_POST[column9]", "$_POST[column10]"); ?> <form name="form1" method="post" action=""> Column 1 - <label> <select name="column1" id="column1"> <option value="">Select The Value of Column 1</option> <?php foreach ($fields as $field) { echo "<option value='$field'"; if ($_POST['column1'] == $field) { echo " selected"; } echo ">$field</option>\n"; } ?> </select> </label><br> <br> <?php if (isset($_POST['column1'])) { echo 'Column 2 - <select name="column2" id="column2">'; $column_array[] = $_POST['column1']; $array_diff = array_diff($fields,$column_array); if (isset($_POST['column2'])) { echo "$_POST[column1]"; } else { foreach ($array_diff as $fields) { echo "<option value='$fields'"; if ($_POST['column2'] == $fields) { echo " selected"; } echo ">$fields</option>\n"; } } } echo "</select>"; ?> <br /><br /> <label> <input type="submit" name="button" id="button" value="Submit"> </label> </form> Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 20, 2012 Share Posted September 20, 2012 You will have to use AJAX for that. jQuery is easy to pick up, but if you don't want to spend the time to learn it, hire someone to do it for you. However, rather than doing all those select boxes, I would use a jQuery sortable list. http://docs.jquery.com/UI/Sortable http://jqueryui.com/demos/sortable/ Quote Link to comment 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.