Jump to content

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/84145-solved-noob-arraymenu-question/
Share on other sites

<?php

  if (isset($_POST['submit'])) {
    switch ($_POST['Cancellation Message'])) {
      case 'foo':
        // do foo
        break;
      case 'bar':
        // do bar
        break;
      default:
        // do default
    }
  }

?>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.