|
Posted by David Haynes on 05/19/06 04:43
Justin Koivisto wrote:
> Patrick wrote:
>> Hello All,
>>
>> Kind of new to PHP. I have an html form where a person inputs a date
>> via a drop down select. How do I make php put a zero in front of the
>> numbers 1-9 ie. 01 02 03 when writing to the file? I have tried making
>> the value="01" etc. but this doesn't work. Below is a snippet of my
>> form and the code I am using to write to the file. I hope I have made
>> myself clear enough. Your help is greatly appreciated.
>>
>>
>> //form part
>> <select class="inform" name="logday">
>> <option value="1">1
>> <option value="2">2
>> <option value="3">3
>> <option value="4">4
>> <option value="5">5
>> <option value="6">6
>> <option value="7">7
>> <option value="8">8
>> <option value="9">9
>> <option value="10">10
>> etc,
>>
>> //code part
>> fputs($out,"$_POST[logday] ");
>
> use something more like:
> fputs($out,sprintf('%02d',intval($_POST['logday'])));
or
fprintf($out, '%02d', $_POST['logday']);
Also, for kicks, the form part could be:
<select class="inform" name="logday">
<?php
foreach( range(1, 10) as $v ) {
printf("<option value="%d">%d</option>\n", $v);
}
?>
-david-
Navigation:
[Reply to this message]
|