Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine multiple fields to one value for form submission

Continuing from my earlier question, how can I combine the month, day, and year <select>s into a single "date" value, so that it arrives at my PHP script as

$_POST['date'], in MySQL format YYYY-MM-DD?

like image 497
Austin Hyde Avatar asked Nov 27 '22 23:11

Austin Hyde


1 Answers

You could use a hidden field and build its value onSubmit, but if I were you, I'd simply use the array notation in the name attribute, and implode the array with '-' as glue : like this

<select name="date[year]">
...
<select name="date[month]">
...
<select name="date[day]">
...

php:

$date = implode('-', $_POST['date'])
//validate date format here
like image 69
greg0ire Avatar answered Feb 16 '23 01:02

greg0ire