Page 1 of 1

PHP Variables & HTML forms

Posted: Tue Jul 22, 2003 11:50 am
by BigJon2001
I thought this was going to be a simple problem, but its stumped me & others for days. Please, anyone, sugestions welcome...

I had a form (on a php page) with...
<td>DateOfBirth(yyyy-mm-dd)</td>
<td><input name="dateofbirth"/> ......bla bla This works...
Now i have dropdowns and a hidden field...
<td><select name="mydobday"><option>01</option>
<td><select name="mydobmth"><option>01</option>
<td><select name="mydobyr"<option>1941 </option>
<input name="dateofbirth" type="hidden" value="<?php echo $dateofbirth; ?>" />

So the question remains - how do i get the users input into variable $dateofbirth - OR how to i get the users input to be sent on in the same format as the original method.

Extra Info: globals=off.
<php $dateofbirth=$mydobyr."-".$mydobmth."-".$mydobday; ?> and
<?php $_POST['mydobyr']."-".$_POST['$mydobmth']."-".$_POST['$mydobday']; ?>
have been tried at top of page (in php block), inside the form between SELECT and INPUT, and even in the Input's VALUE=

Posted: Tue Jul 22, 2003 12:58 pm
by pootergeist
lose the hidden input and just concatenate a string from the returns of the $_POST vars from the selects (or $_REQUEST or $_GET dependent upon form method)

$dob = $_POST['mydobyr']. '-' .$_POST['mydobmth']. '-' .$_POST['mydobday'];

note: you would need to set your option tags to include a value ...

<select name="mydobday">
<option value="01">1st</option>
<option value="02">2nd</option>
etc
</select>

...

Posted: Tue Jul 22, 2003 1:21 pm
by kettle_drum
If you want to set the hidden variable on the page as the user is entering the data then you will need to do some javascript to set the value onChange() of the drop down boxes.

Easier, would be to just submit the form and then construct the dob on the page that the form submits to.

Another tip that you may want to use is to use for loops to print the values in your <select>'s.

Code: Select all

<?php

for($loop=1;$loop<13; $loop++){
   echo "<option value="".strftime("%m", mktime('0','0','0',$loop,'1'))."">".strftime("%b", mktime('0','0','0',$loop,'1'));
}

?>
It just saves typing out each month in your form. You will also want to do the same with the day and the year.