Form validation for user account creation What would be a cleaner way to write the following?

// Check if add user was attempted
if ($params['submit']) {
    // Verify all fields are filled in
    if (Utilities::checkAllFieldsNotEmpty($params)) {
        // Make sure username is not taken
        if (Admin::checkUsername($params['username'])) {
            // Check if directory is created
            if (Admin::createUsersDirectory($params['username'])) {
                if (Admin::createNewUser($params['name'], $params['username'], $params['password'], $params['admin'])) {
                    Utilities::setMessage("Excellent!", "User was created successfully.", "admin_modal");
                }
            } else {
                Utilities::setMessage("Whoa!", "Directory creation failed.", "admin_modal");
            }
        } else {
            Utilities::setMessage("Whoa!", "Username in use.", "admin_modal");
        }
    } else {
        Utilities::setMessage("Whoa!", "Please fill in all fields", "admin_modal");
    }

    // Return admin view with message
    return $this-&gt;view-&gt;render($response, 'admin/admin.twig', [
        'name' =&gt; $user['name'],
        'message' =&gt; $_SESSION['message'],
        'form' =&gt; [
            'name' =&gt; $params['name'],
            'username' =&gt; $params['username'],
            'admin' =&gt; $params['admin']
        ]
    ]);
}
Don't nest your conditions like this.  Validate the input up front and fail out if need be.

For example that might look like this:

if(empty($params['submit'])) {
   // no parameters set
   // log error, throw exception, etc. as approrpiate
}
if(Utilities::checkAllFieldsNotEmpty($params) === false) {
   // fail out
   // not sure if you really need this condition if you validate each field
   // individually
}
// etc.


Then I would suggest that your Admin class should abstract away the details of user creation away from this script.  Ideally this script could just have something like:

try {
    $user = Admin::createNewUser(...);
} catch (Exception $e) {
    // do something to handle exception
}


And createNewUser() would go through all the logic of for validating user name, setting up directories, etc.  This code should know nothing about what is required to create a "user" outside of whatever information needs to be passed (i.e. user name).