Also wir sollten nun dieses Template haben:
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:
|
{!DOCTYPE}
<html>
<head>
<title>$master_board_name - Charakter bearbeiten</title>
$headinclude
</head>
<body id="bg">
$header
<tr bgcolor="{tablecolora}" id="tablea">
<td><table cellpadding=0 cellspacing=0 border=0 width="100%">
<tr>
<td><smallfont><b><a href="index.php?sid=$session[hash]">$master_board_name</a> » <a href="usercp.php?sid=$session[hash]">Kontrollzentrum von $wbbuserdata[username]</a> » Charakter bearbeiten</b></font></td>
<td align="right"><smallfont><b>$usercbar</b></font></td>
</tr>
</table></td>
</tr>
</table><br>
<form action="usercp.php" method="post"><table cellpadding=4 cellspacing=1 border=0 bgcolor="{tableinbordercolor}" width="{tableinwidth}">
<tr bgcolor="{tablecatcolor}" id="tablecat">
<td colspan=2><normalfont color="{fontcolorthird}"><b>» Charakter bearbeiten</b></font></td>
</tr>
<tr id="tablea" bgcolor="{tablecolora}">
<td ><normalfont><b>Geburtsdatum:</b></font></td>
<td><table>
<tr>
<td><smallfont>Tag</font></td>
<td><smallfont>Monat</font></td>
<td><smallfont>Jahr</font></td>
</tr>
<tr>
<td><select name="cr_day">
<option value="0"></option>
$day_options
</select></td>
<td><select name="cr_month">
<option value="0"></option>
$month_options
</select></td>
<td><input type="text" class="input" name="cr_year" value="$cr_year" maxlength="4" size=5></td>
</tr>
</table></td>
</tr>
</table><br>
<p align="center"><input class="input" type="submit" value="Speichern"> <input class="input" type="reset" value="Zurücksetzen"></p>
<input type="hidden" name="action" value="$action">
<input type="hidden" name="send" value="send">
<input type="hidden" name="sid" value="$session[hash]">
</form>
$footer
</body>
</html> |
|
Nun müssen wir "Optionen" erstellen.
Das ist im Prinzip ganz einfach:
php: |
1:
2:
|
for($i=1;$i<=31;$i++) $day_options.=makeoption($i,$i,$cr_day);
for($i=1;$i<=12;$i++) $month_options.=makeoption($i,getmonth($i),$cr_month); |
|
Unser "php"-Code sollte nun so aussehen:
php: |
1:
2:
3:
4:
5:
6:
7:
|
if($action=="character_edit") {
for($i=1;$i<=31;$i++) $day_options.=makeoption($i,$i,$cr_day);
for($i=1;$i<=12;$i++) $month_options.=makeoption($i,getmonth($i),$cr_month);
eval("\$tpl->output(\"".$tpl->get("usercp_character_edit")."\");");
} |
|
Das sind einfach zwei Schleifen die von 1 - 31 bzw. 1 - 12 laufen und unsere Variablen "$day_options" bzw. "$month_options" mit den entsprechenden Daten füllen.
"makeoption" ist eine Funktion vom wbb, die einen Tag vorauswählt, falls der Benutzer schon bereits etwas ausgwählt hat.
Nun bereiten wir den Eintrag in die Datenbank vor.
Dies bedeutet, dass wir vom Formular, das bereits existiert, Daten an die "php"-Datei übergeben.
Die Übergabe erfolgt ebenfalls schon, wir müssen nur mehr der "php"-Datei sagen, wie sie damit umgehen soll.
Somit brauchen wir etwas wie:
php: |
1:
2:
3:
|
if(isset($_POST['cr_day'])) $cr_day = trim($_POST['cr_day']);
if(isset($_POST['cr_month'])) $cr_month = trim($_POST['cr_month']);
if(isset($_POST['cr_year'])) $cr_year = trim($_POST['cr_year']); |
|
Bekommen wir also per "method=post" Daten überliefert, stehen uns jene nun in den Variablen "$cr_day, $cr_month und $cr_year" zu Verfügung.
Wir könnten auch direkt mit "$_POST['cr_day'],$_POST['cr_month'] und $_POST['cr_year']" arbeiten, da jene "Variablen" bereits unseren gewünschten Inhalt besitzen.
Ist reine Geschmackssache, was man nun verwendet und wie man damit weiter umgeht.
Somit haben wir einen php Code, der wie folgt aussieht:
php: |
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
|
if($action=="character_edit") {
if(isset($_POST['send'])) {
if(isset($_POST['cr_day'])) $cr_day = trim($_POST['cr_day']);
if(isset($_POST['cr_month'])) $cr_month = trim($_POST['cr_month']);
if(isset($_POST['cr_year'])) $cr_year = trim($_POST['cr_year']);
}
for($i=1;$i<=31;$i++) $day_options.=makeoption($i,$i,$cr_day);
for($i=1;$i<=12;$i++) $month_options.=makeoption($i,getmonth($i),$cr_month);
eval("\$tpl->output(\"".$tpl->get("usercp_character_edit")."\");");
} |
|
Die Zeile "if(isset($_POST['send']))" sagt nur, dass der Code innerhalb seiner geschweiften Klammern nur dann ausgeführt wird, wenn auch wirklich das Formular abgesendet wurde.
Also mit einen Klick auf "Speichern".
Eine Idee wie es nun weitergeht bzw. was als nächstes Interessant wäre?