-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.php
84 lines (73 loc) · 1.76 KB
/
add.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
include('kanji.php');
//mb_internal_encoding('UTF-8');
$required = array(
'kanji',
'pronunciation',
'english_translation',
);
if (!empty($_POST)) {
$missing = false;
foreach ($_POST as $key => $value) {
if (empty($value) && $key != 'link') {
$missing = true;
}
}
if (!$missing) {
$kanji = new Kanji($_POST);
$kanji->insert();
header('Location: manage.php');
}
}
show_form($required);
function show_form($required) { ?>
<!doctype html>
<html>
<head>
<title>Add Kanji</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>Add Kanji</h1>
<form action='add.php' method='post'>
<table>
<tr>
<td>Kanji</td>
<td><input name="kanji" type="text"
value="<?php echo $_POST['kanji']?>" /></td>
</tr>
<tr>
<td>Pronunciation (in hiragana)</td>
<td><input name="pronunciation" type="text"
value="<?php echo $_POST['pronunciation']?>" /></td>
</tr>
<tr>
<td>English translation</td>
<td><input name="english_translation" type="text"
value="<?php echo $_POST['english_translation']?>" /></td>
</tr>
<tr>
<td>Link (optional)</td>
<td><input name="link" type="text"
value="<?php echo $_POST['link']?>"/></td>
</tr>
</table>
<input type="submit" value="Submit" />
</form>
<span class="error"><?php show_error_text($required); ?></span>
</body>
</html><?php
}
function show_error_text($required) {
if (!empty($_POST)) {
echo 'You are missing: <blockquote>';
foreach ($required as $key) {
if (empty($_POST[$key])) {
echo $key.'<br />';
}
}
echo '</blockquote>';
}
}
?>