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=
PHP Variables & HTML forms
Moderator: General Moderators
-
pootergeist
- Forum Contributor
- Posts: 273
- Joined: Thu Feb 27, 2003 7:22 am
- Location: UK
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>
$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>
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
...
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.
It just saves typing out each month in your form. You will also want to do the same with the day and the year.
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'));
}
?>