Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function add()
- {
- $user = new User();
- $title = 'Add user';
- $errors = [];
- //Check errors when posting
- if(!empty($_POST)){
- if( !preg_match('/^[A-Za-z ]+$/', $_POST['fullname'])){
- $errors["fullname"] = "Fullname is required";
- }
- if(!is_null('email') && !filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
- $errors["email"] = "Email is required";
- }
- if(strlen($_POST["password"]) < 8){
- $errors["password"] = "Password is required";
- }
- if(strcmp($_POST["password"], $_POST["password_confirmation"])!=0){
- $errors["password_confirmation"] = "Password confirmation must be equal to password";
- }
- $user_type = $_POST['user_type'] ?? null;
- if( is_null($user_type) || $user_type <0 || $user_type > 2){
- $errors["user_type"] = "Type is required";
- }
- //se nao houver erros gg
- if(!$errors){
- User::add($user = new User($_POST));
- }
- if (isset($_POST['cancel'])){
- return header('Location: user.php');
- }
- }
- return render_view('users.add', compact('title', 'user', 'errors'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement