-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcreate.php
74 lines (59 loc) · 2.33 KB
/
create.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
<?php
$page_title = "Create | PHP Practice";
include "inc/header.php";
include "utility/autoload.php";
$crud = new Crud;
$validation = new Validation;
if($_SERVER['REQUEST_METHOD'] == "POST"):
$err_message = $validation->check_empty_field($_POST, ['f_name', 'f_email', 'f_website']);
$crud->user_name = $_POST['f_name'];
$crud->user_email = $_POST['f_email'];
$crud->user_website = $_POST['f_website'];
$crud->user_comment = $_POST['f_comment'];
//Validation Starts
$check_data = $validation->is_valid_data($crud->user_name);
$check_email = $validation->is_valid_email($crud->user_email);
$check_web = $validation->is_valid_website($crud->user_website);
if($err_message != null):
echo $err_message;
elseif($check_data):
echo "Please provide name in letters";
elseif($check_email):
echo "Please provide proper email";
elseif($check_web):
echo "Please provide proper web address";
else:
$store_data = $crud->create();
if($store_data):
header("location:index.php?record_add_status=success");
endif;
endif;
endif;
?>
<div class="bottom-margin">
<a href="index.php"><button>Back to Record</button></a>
</div>
<div class="form-data">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" enctype="multipart/form-data">
<div>
<label for="name">Name</label>
<input type="text" name="f_name" id="name" value="<?php echo isset($_POST["f_name"]) ? $_POST["f_name"] : ''; ?>">
</div>
<div>
<label for="email">Email</label>
<input type="email" name="f_email" id="email" value="<?php echo isset($_POST["f_email"]) ? $_POST["f_email"] : ''; ?>">
</div>
<div>
<label for="website">Website</label>
<input type="website" name="f_website" id="website" value="<?php echo isset($_POST["f_website"]) ? $_POST["f_website"] : ''; ?>">
</div>
<div>
<label for="comment">Comment</label>
<textarea name="f_comment" id="comment"><?php echo isset($_POST["f_comment"]) ? $_POST["f_comment"] : ''; ?></textarea>
</div>
<div>
<button type="submit" name="submit">Submit</button>
</div>
</form>
</div>
<?php include "inc/footer.php"; ?>