Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $title = 'Add user';
- $errors = [];
- if (!empty($_POST)) {
- $fullname = $_POST["fullname"] ?? "";
- $email = $_POST["email"] ?? "";
- $user_type = $_POST["user_type"] ?? "";
- $password = $_POST["password"] ?? "";
- $password_confirmation = $_POST["password_confirmation"] ?? "";
- if (empty($fullname)) {
- $errors["fullname"] = "Fullname is required";
- } else if (!filter_var($fullname, FILTER_VALIDATE_REGEXP, array("options" => ["regexp" => "/^[a-zA-Z\s]*$/"]))) {
- $errors["fullname"] = "Fullname must only contain letters and spaces";
- }
- if (empty($email)) {
- $errors["email"] = "Email is required";
- } else if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- $errors["email"] = "Email is not valid";
- }
- if (empty($password)) {
- $errors["password"] = "Email is required";
- } else if (strlen($password) < 8) {
- $errors["password"] = "Password must have at least 8 characters";
- } else if ($password != $password_confirmation) {
- $errors["password_confirmation"] = "The passwords do not match";
- }
- if (empty($user_type)) {
- $errors["user_type"] = "Type is required";
- } else if (!filter_var($user_type, FILTER_VALIDATE_INT, array('options' => ["min_range" => 0, "max_range"=> 2]))) {
- $errors["user_type"] = "Type is not valid";
- }
- }
- if (empty($errors)) {
- render_view('users.add', compact('title','user','errors'));
- } else {
- $user = new User(['user_id' => 0, 'email' => $email, 'password' => $password, 'fullname' => $fullname, 'type' => $user_type, 'registered_at' => date("Y-m-d H:i:s")]);
- User::add($user);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement