RE: [PHP] Why does this happen?
| From: | Ford, Mike [LSS] | Date: | Mon, 10 Feb 2003 13:20:17 +0000 |
| Subject: | RE: [PHP] Why does this happen? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-135042@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Ernest E Vogelsinger [mailto:ernest@vogelsinger.at]
> Sent: 09 February 2003 14:39
[OP snipped]
> I don't know much about CF, but in plain HTML as you show
> here you have 3
> different form input (select) fields sharing the same name. Thus the
> browser will transmit only one of the three input (select) fields upon
> submit (it is undefined which field will be sent, but most
> browsers will
> transmit the last value).
No, that's not true. The browser will transmit them all -- it's up to
whatever's receiving the POST to decide what to do with the duplicates.
ColdFusion obviously glues them together, whereas PHP ignores all except the
last.
> <form name="form1" method="post" action="">
> Year
> <select name="date[Y]" onSelect="return check_submit()">
> <option selected value=2002>2002</option>
> </select>
> Month
> <select name="date[M]">
> <option selected value=12>12</option>
> </select>
> Day
> <select name="date[D]">
> <option selected value=25>25</option>
> </select>
> <input type="submit" name="textfield">
> </form>
>
> In your receiving script you would have an associative array
> named "date"
> in the $_REQUEST structure:
>
> $date_received = $_REQUEST['date'];
> $year = $date_received['Y'];
> $month = $date_received['M'];
> $day = $date_received['D'];
That's one way to do it. Personally, I'd just name the fields date_year,
date_month and date_day -- using an array here seems like unnecessary
complexity. I'd save arrays for when I really need them -- like if I have a
multi-row form where each row has year/month/day fields.
Cheers!
Mike
---------------------------------------------------------------------
Mike Ford, Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS, LS6 3QS, United Kingdom
Email: m.ford@lmu.ac.uk
Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211