Waterskier19 Posted January 2, 2008 Share Posted January 2, 2008 Hi all, Very new to PhP, but have a lot of experience with C++ - so I have a good understanding of Arrays in general, however - I am having some problems with a form that I am trying to create. Basically, what I have is a menu created from an array [pre] $cancellationMessage = array(0 => 'Select Notice', 'Weather Delay', 'Weather Cancellation', 'Other'); echo "Cancellation Notice:\n"; echo '<select name="Cancellation Message">'; foreach ($cancellationMessage as $key => $choice) { echo "<option value=\"$key\"> $choice</option>\n"; } echo '</select>'; [/pre] This creates the menu for me without a problem - but my question is, when the user hits POST - how do I find what the user chose as his selection? ($choice always seems to be the last option in the array) Basically, if its a certain selection, I want to do special stuff . . . i.e. if (usersSelection == "Weather Delay") { then do delay stuff; } else { do something else } I'm obviously missing something - Any help would be appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/84145-solved-noob-arraymenu-question/ Share on other sites More sharing options...
trq Posted January 2, 2008 Share Posted January 2, 2008 <?php if (isset($_POST['submit'])) { switch ($_POST['Cancellation Message'])) { case 'foo': // do foo break; case 'bar': // do bar break; default: // do default } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84145-solved-noob-arraymenu-question/#findComment-428335 Share on other sites More sharing options...
Waterskier19 Posted January 2, 2008 Author Share Posted January 2, 2008 Thanks for your help, but now I have a follow up question. Is there anyway to check user input before the Post button is pressed (i.e. as soon as the option menu is selected by the user, check the values)? Basically I want to do the following: - As soon as the user selects cancellationMessage from the menu, check the type and if it is "Delay" enable (or create dynamically) - a text-box that will prompt the user to select the delay time. Is this possible? Sorry for my lack of experience with what Php can/can't do. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/84145-solved-noob-arraymenu-question/#findComment-428353 Share on other sites More sharing options...
kenrbnsn Posted January 2, 2008 Share Posted January 2, 2008 That can only be done using Javascript. Since PHP is executed on the server, it doesn't see any data until the user submits the form. Ken Quote Link to comment https://forums.phpfreaks.com/topic/84145-solved-noob-arraymenu-question/#findComment-428361 Share on other sites More sharing options...
duclet Posted January 2, 2008 Share Posted January 2, 2008 That has to be done with AJAX. My suggestion, get this to work correctly first, then tackle on the advanced stuff later. Working in simple steps makes it much easier. Quote Link to comment https://forums.phpfreaks.com/topic/84145-solved-noob-arraymenu-question/#findComment-428364 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.