LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Web form retrieve <select><option> with PHP (https://www.linuxquestions.org/questions/programming-9/web-form-retrieve-select-option-with-php-744226/)

esteeven 07-31-2009 03:04 PM

Web form retrieve <select><option> with PHP
 
I am either very stupid or very very tired but I cannot quite understand how to retrieve data from a web form if the data is in a <select> box. The data is being sent via email.

PHP is VERY new to me. I have managed to understand this syntax :

$surname = $_POST['surname']

and this has led to :

$body = "First Name:$firstname\n surname:$surname\n E-Mail:$email\n address:\n$address\n" ;

My web form is emailed perfectly. I need now to get data from :

<select>
<option>yes</option>
<option>no</options>
</select>

I don't understand how to refer to this in my php. It's almost as though <select> should have an id. <select name="choice"> ??

Hmmm! I am really tired. :o I don't know if my question even makes sense. I love it when I am completely in the dark.

Thanks in advance!!!!!

graemef 08-01-2009 01:08 AM

You need to add the name attribute then the selected item will be returned in the $_POST array with the name being the key.

esteeven 08-01-2009 03:18 AM

I reread my post this morning and kicked myself (twice.) I had answered myself. Many thanks graemef : your response confirmed everything for me. It works!!

Now I need to understand how to report an error if a registrant does not tick a specific box.

Simple things sometimes takes massive leaps of understanding.

Thanks!


All times are GMT -5. The time now is 05:54 AM.