Log in

View Full Version : PHP Contactform


Artem
Jan 18, 2009, 03:23 AM
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.

retsoksirhc
Jan 18, 2009, 09:46 AM
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']

retsoksirhc
Jan 18, 2009, 09:49 AM
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.