datum in form selecteren > MYSQL
Ik ben nu reeds 7 dagen aan het zoeken naar een methode om een form te maken waarin ik door middel van drop down selectie de dag maand en het jaartal kan kiezen. Daarna in het opgeroepen add.php form die info in een date veld van myql kan zetten
Uiteraard heb ik vele snippets etc bekeken gedownload etc echter nog steeds niet tot een oplossing gekomen.
Waar ik om vraag is niet even een losse snippet, maar een DUIDELIJKE uitleg/voorbeeld van
In het formulier:
INPUT TYPE=TEXT VALUE=VANDAAG losse pull downs met dag maan jaar.
Daarnaast de code die ik dan in het add formulier moet zetten om bovenstaande invoer toe te voegen
$datum = code van datum uit formulier
edit: want ik neem dat je wel al een form met drops hebt.
Gewijzigd op 31/03/2006 18:00:00 door Kalle P
Het veld in de databse heet uiteraand Datum. (tabel
Ik heb de volgende functie opgehaald en aangepast :
Bestand dateselect.php
Creates three SELECT form fields Month Day and Year
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
function DateSelector($inName, $useDate=0)
{
/* create array so we can name months */
$monthName = array(1=> "januari", "februari", "maart",
"april", "mei", "juni", "Juli", "augustus",
"september", "oktober", "november", "december");
/* if date invalid or not supplied, use current time */
if($useDate == 0)
{
$useDate = Time();
}
/* make day selector */
echo "<SELECT NAME=" . $inName . "Day>\n";
for($currentDay=1; $currentDay <= 31; $currentDay++)
{
echo "<OPTION VALUE=\"$currentDay\"";
if(intval(date( "d", $useDate))==$currentDay)
{
echo " SELECTED";
}
echo ">$currentDay\n";
}
echo "</SELECT>";
/* make month selector */
echo "<SELECT NAME=" . $inName . "Month>\n";
for($currentMonth = 1; $currentMonth <= 12; $currentMonth++)
{
echo "<OPTION VALUE=\"";
echo intval($currentMonth);
echo "\"";
if(intval(date( "m", $useDate))==$currentMonth)
{
echo " SELECTED";
}
echo ">" . $monthName[$currentMonth] . "\n";
}
echo "</SELECT>";
/* make year selector */
echo "<SELECT NAME=" . $inName . "Year>\n";
$startYear = date( "Y", $useDate);
for($currentYear = $startYear - 5; $currentYear <= $startYear+5;$currentYear++)
{
echo "<OPTION VALUE=\"$currentYear\"";
if(date( "Y", $useDate)==$currentYear)
{
echo " SELECTED";
}
echo ">$currentYear\n";
}
echo "</SELECT>";
}
?>
function DateSelector($inName, $useDate=0)
{
/* create array so we can name months */
$monthName = array(1=> "januari", "februari", "maart",
"april", "mei", "juni", "Juli", "augustus",
"september", "oktober", "november", "december");
/* if date invalid or not supplied, use current time */
if($useDate == 0)
{
$useDate = Time();
}
/* make day selector */
echo "<SELECT NAME=" . $inName . "Day>\n";
for($currentDay=1; $currentDay <= 31; $currentDay++)
{
echo "<OPTION VALUE=\"$currentDay\"";
if(intval(date( "d", $useDate))==$currentDay)
{
echo " SELECTED";
}
echo ">$currentDay\n";
}
echo "</SELECT>";
/* make month selector */
echo "<SELECT NAME=" . $inName . "Month>\n";
for($currentMonth = 1; $currentMonth <= 12; $currentMonth++)
{
echo "<OPTION VALUE=\"";
echo intval($currentMonth);
echo "\"";
if(intval(date( "m", $useDate))==$currentMonth)
{
echo " SELECTED";
}
echo ">" . $monthName[$currentMonth] . "\n";
}
echo "</SELECT>";
/* make year selector */
echo "<SELECT NAME=" . $inName . "Year>\n";
$startYear = date( "Y", $useDate);
for($currentYear = $startYear - 5; $currentYear <= $startYear+5;$currentYear++)
{
echo "<OPTION VALUE=\"$currentYear\"";
if(date( "Y", $useDate)==$currentYear)
{
echo " SELECTED";
}
echo ">$currentYear\n";
}
echo "</SELECT>";
}
?>
Het formulier :
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<html>
<body>
<?php include("dateselect.php"); ?>
<form method="post" action="add.php">
<TABLE>
<TR>
<TD>datum:</TD>
<TD>
<!-- You can use PHP functions to automatically get the value of date -->
<INPUT TYPE='TEXT' NAME='date' <?php $DateSelector('day','month','year'); ?> >
</TD>
</TR>
<TR>
<TD></TD><br>
<TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
</form>
<body>
<html>
<body>
<?php include("dateselect.php"); ?>
<form method="post" action="add.php">
<TABLE>
<TR>
<TD>datum:</TD>
<TD>
<!-- You can use PHP functions to automatically get the value of date -->
<INPUT TYPE='TEXT' NAME='date' <?php $DateSelector('day','month','year'); ?> >
</TD>
</TR>
<TR>
<TD></TD><br>
<TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
</form>
<body>
<html>
Gewijzigd op 31/03/2006 18:33:00 door Ton
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<html>
<body>
<?php include("dateselect.php"); ?>
<form method="post" action="add.php">
<TABLE>
<TR>
<TD>datum:</TD>
<TD>
<!-- You can use PHP functions to automatically get the value of date -->
<?php DateSelector('mySelect'); ?>
</TD>
</TR>
<TR>
<TD></TD><br>
<TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
</form>
<body>
<html>
<body>
<?php include("dateselect.php"); ?>
<form method="post" action="add.php">
<TABLE>
<TR>
<TD>datum:</TD>
<TD>
<!-- You can use PHP functions to automatically get the value of date -->
<?php DateSelector('mySelect'); ?>
</TD>
</TR>
<TR>
<TD></TD><br>
<TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
</form>
<body>
<html>
edit: kleine wijziging in de code
Gewijzigd op 31/03/2006 18:36:00 door Jan Koehoorn
Op deze manier krijg ik dus wel die selectie maar gaat er geen variabele mee naar het add formulier..
Groetjes,
Ton
$_POST['mySelectDay']
$_POST['mySelectMonth']
$_POST['mySelectYear']
Ton