Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   PHP (https://www.askmehelpdesk.com/forumdisplay.php?f=454)
-   -   PHP Contactform (https://www.askmehelpdesk.com/showthread.php?t=305144)

  • Jan 18, 2009, 03:23 AM
    Artem
    PHP Contactform
    Hi guys,


    Got a question about something I need for my contactform.
    Currently I have 3 fields, which work fine and I receive all properly in my mailbox.

    But now I'd like to add a drop-downmenu using <select><option></option></select>.

    I just can't figure out what PHP lines to write, so I can see which of the options the client has chosen...



    Help much appreciated.
  • Jan 18, 2009, 09:46 AM
    retsoksirhc

    It's basically just like any other POST form. You do the <select name='varDropdown'> the get it in a variable name, and you assign a value to each option. Generally I assign the value the same as what the option is displaying, like:
    <option value="option1">Option1</option>
    <option value="option2">Option2</option>

    Then, depending on if you have register globals on or off in PHP, you would access it with:
    $varDropdown
    OR
    $_POST['varDropdown']
  • Jan 18, 2009, 09:49 AM
    retsoksirhc
    Okay looking back it might not be quite clear. If the user chose Option1 and submitted the form, $_POST['varDropdown'] (or $varDropdown) is equal to the string 'option1'
    Likewise, if Option2 was chosen from the dropdown, $_POST['varDropdown'] would be equal to 'option2'

    You can check the output with print_r($_POST), although I tend to use echo(nl2br(print_r($_POST,TRUE))) to check output because I like the format better.

  • All times are GMT -7. The time now is 06:14 PM.