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
85
86
<?php
require_once 'Database.php'; // Pastikan file Database.php berada di direktori yang sama atau sesuaikan path-nya
require_once 'upload_form.php';
class Form {
private $conn;
public function __construct() {
$database = new Database();
$this->conn = $database->conn;
}
public function text($name, $label) {
return "<label for='$name'>$label:</label>
<input type='text' id='$name' name='$name' required><br>";
}
public function password($name, $label) {
return "<label for='$name'>$label:</label>
<input type='password' id='$name' name='$name' required><br>";
}
public function radio($name, $label, $options) {
$html = "<label>$label:</label><br>";
foreach ($options as $value => $text) {
$html .= "<input type='radio' id='$name-$value' name='$name' value='$value' required>
<label for='$name-$value'>$text</label><br>";
}
return $html;
}
public function checkbox($name, $label) {
return "<input type='checkbox' id='$name' name='$name'>
<label for='$name'>$label</label><br>";
}
public function select($name, $label, $options) {
$html = "<label for='$name'>$label:</label>
<select id='$name' name='$name' required>";
foreach ($options as $value => $text) {
$html .= "<option value='$value'>$text</option>";
}
$html .= "</select><br>";
return $html;
}
public function textarea($name, $label) {
return "<label for='$name'>$label:</label><br>
<textarea id='$name' name='$name' required></textarea><br>";
}
public function file($name, $label) {
return "<label for='$name'>$label:</label>
<input type='file' id='$name' name='$name' required><br>";
}
public function submitForm($data) {
try {
$sql = "INSERT INTO upload (nama_channel, judul, visibilitas, deskripsi)
VALUES (:nama_channel, :judul, :visibilitas, :deskripsi)";
$stmt = $this->conn->prepare($sql);
$stmt->bindParam(':nama_channel', $data['nama_channel']);
$stmt->bindParam(':judul', $data['judul']);
$stmt->bindParam(':visibilitas', $data['visibilitas']);
$stmt->bindParam(':deskripsi', $data['deskripsi']);
$stmt->execute();
return "Data berhasil disimpan";
} catch(PDOException $e) {
return "Error: " . $e->getMessage();
}
}
}
// Penggunaan kelas Form
$form = new Form();
// Proses form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$result = $form->submitForm($_POST);
echo $result;
}
?>