-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.php
41 lines (36 loc) · 1.03 KB
/
action.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
<?php
header("Content-type: application/json");
if(isset($_POST['submit'])){
// For delay effect
sleep(1);
// For storing the error fields' name
$errorFields = array();
// Validate fields
if($_POST['name']==""){
// Array key must be the same like input name.
$errorFields['name'] = "Please fill name!";
}
if($_POST['address']==""){
// Array key must be the same like input name.
$errorFields['address'] = "Please fill address!";
}
// Check error fields count
if(count($errorFields)==0){
// Success message
$result['status'] = "success";
$result['message'] = "Your data has been saved.";
// Form will be cleared
$result['clearForm'] = true;
}
else{
// Failed message
$result['status'] = "failed";
$result['message'] = "Please fill all fields correctly!";
// Form will not be cleared
$result['clearForm'] = false;
}
// Error fields list
$result['errorFields'] = $errorFields;
// Return message and error fields is JSON format
echo json_encode($result);
}