0) redirect('/'); echo render('layouts/basic', ['view' => 'pages/chars/first']); } /** * Create a player for the currently logged in user. */ function char_controller_create_post(): void { gate(false); csrf_ensure(); $errors = []; $name = $_POST['name'] ?? ''; // Trim the input. $name = trim($name); /* A name is required. A name must be between 3 and 18 characters. A name must contain only alphanumeric characters and spaces. */ if (empty($name) || strlen($name) < 3 || strlen($name) > 18 || !ctype_alnum(str_replace(' ', '', $name))) { $errors['name'][] = 'Name is required and must be between 3 and 18 characters long and contain only alphanumeric characters and spaces.'; } /* A player's name must be unique. */ if (char_nameExists($name)) $errors['name'][] = 'Name is already taken.'; // If there are errors at this point, send them to the page with errors flashed. if (!empty($errors)) { flash('errors', $errors); redirect('/'); } // Create the player $player = char_create(user('id'), $name); if ($player === false) router_error(400); // Create the auxiliary tables char_location_create($player); char_wallet_create($player); char_gear_create($player); redirect('/'); }