jeppers Posted October 25, 2007 Share Posted October 25, 2007 My problem is that i have a pull down boxes with day/month/year in them i would like to be able to keep that format. at the moment when choosing the values (example shown below) 3 august 2007 would pint out as 3 8 0. i want to no how to keep the format they are originally chosen wanted outcome 03 august 2007 how i retrieved the variables Code: $days = ($_POST['days']); $months = ($_POST['months']); $years = ($_POST['years'] as string); //create a date variable $date = $days .''. $months .''. $years; echo "$date"; can u help thanks Quote Link to comment https://forums.phpfreaks.com/topic/74799-solved-how-do-u-keep-date-format-when-passing-through-a-form/ Share on other sites More sharing options...
premiso Posted October 25, 2007 Share Posted October 25, 2007 Look into www.php.net/date and www.php.net/mktime Quote Link to comment https://forums.phpfreaks.com/topic/74799-solved-how-do-u-keep-date-format-when-passing-through-a-form/#findComment-378187 Share on other sites More sharing options...
thebadbad Posted October 25, 2007 Share Posted October 25, 2007 I think you misunderstood him. I guess your problem is mostly your HTML (although you didn't show it). The drop-down list should look like this in your case: <select name="days"> <option value="01">01</option> <option value="02">02</option> <option value="03">03</option> ... </select> <select name="months"> <option value="january">January</option> <option value="february">February</option> <option value="march">March</option> ... </select> <select name="years"> <option value="2000">2000</option> <option value="2001">2001</option> <option value="2002">2002</option> ... </select> And the PHP: <?php $days = $_POST['days']; $months = $_POST['months']; $years = $_POST['years']; $date = $days.' '.$months.' '.$years; echo $date; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74799-solved-how-do-u-keep-date-format-when-passing-through-a-form/#findComment-378198 Share on other sites More sharing options...
jeppers Posted October 25, 2007 Author Share Posted October 25, 2007 i used a forloop which i think may be the problem //make the months array $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); //make the days and years array $days = range (0, 31); $years = range (2007, 2020); //make the days pull down menu echo '<select name="days">'; foreach ($days as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; //make that months pull down menus echo '<select name="months">'; foreach ($months as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; //make the year pull down menu echo '<select name="years">'; foreach ($years as $key => $value) { echo "<option value=\"$key\">$value</option>\n"; } echo '</select>'; any clues Quote Link to comment https://forums.phpfreaks.com/topic/74799-solved-how-do-u-keep-date-format-when-passing-through-a-form/#findComment-378202 Share on other sites More sharing options...
jeppers Posted October 25, 2007 Author Share Posted October 25, 2007 so the question is can the data format be collected from the loops and used as they look before the form is processed Quote Link to comment https://forums.phpfreaks.com/topic/74799-solved-how-do-u-keep-date-format-when-passing-through-a-form/#findComment-378207 Share on other sites More sharing options...
thebadbad Posted October 25, 2007 Share Posted October 25, 2007 Your code is fine, you just need to change $key to $value 3 places to get what you want. And the days range should be from 1-31, not from 0-31. If you want months to be in lowercase when sent, use strtolower(). <?php //make the months array $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); //make the days and years array $days = range (1, 31); $years = range (2007, 2020); //make the days pull down menu echo '<select name="days">'; foreach ($days as $key => $value) { echo "<option value=\"$value\">$value</option>\n"; } echo '</select>'; //make that months pull down menus echo '<select name="months">'; foreach ($months as $key => $value) { echo "<option value=\"$value\">$value</option>\n"; } echo '</select>'; //make the year pull down menu echo '<select name="years">'; foreach ($years as $key => $value) { echo "<option value=\"$value\">$value</option>\n"; } echo '</select>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74799-solved-how-do-u-keep-date-format-when-passing-through-a-form/#findComment-378210 Share on other sites More sharing options...
jeppers Posted October 25, 2007 Author Share Posted October 25, 2007 Not sure what u mean could you spell it out to me Quote Link to comment https://forums.phpfreaks.com/topic/74799-solved-how-do-u-keep-date-format-when-passing-through-a-form/#findComment-378213 Share on other sites More sharing options...
jeppers Posted October 25, 2007 Author Share Posted October 25, 2007 thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/74799-solved-how-do-u-keep-date-format-when-passing-through-a-form/#findComment-378214 Share on other sites More sharing options...
thebadbad Posted October 25, 2007 Share Posted October 25, 2007 No problem What I meant with changing the $key with $value: <option value="This is sent to the server/whatever">This is shown in the drop-down</option> You had from 1-12 ($key) sent to the server, and jan-dec ($value) shown in the drop-down. About the lowercase-thing, just do like this in the months-"foreach": echo "<option value=\"strtolower($value)\">$value</option>\n"; Quote Link to comment https://forums.phpfreaks.com/topic/74799-solved-how-do-u-keep-date-format-when-passing-through-a-form/#findComment-378219 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.