private function processAddStaff() { $this->firstName = trim($_POST['first-name']); $this->lastName = trim($_POST['last-name']); $this->jobTitle = trim($_POST['job-title']); $this->bio = trim($_POST['bio']); // Validate the form to make sure the user has provided all the appropriate fields if (strlen($this->firstName) < 2) { $this->firstNameError = 'First name needs to be at least 2 characters.'; } elseif (strlen($this->firstName > 20)) { $this->firstNameError = 'First name is limited to 20 characters.'; } elseif (!preg_match('/^[\\w.\\-\\s]{2,20}$/', $this->firstName)) { $this->firstNameError = 'First Name is limited to letters, hyphens and fullstops.'; } if (strlen($this->lastName) < 2) { $this->lastNameError = 'Last name needs to be at least 2 characters.'; } elseif (strlen($this->lastName > 20)) { $this->lastNameError = 'Last name is limited to 20 characters.'; } elseif (!preg_match('/^[\\w.\\-\\s]{2,20}$/', $this->lastName)) { $this->lastNameError = 'Last Name can only include letters, hyphens & fullstops.'; } if (strlen($this->jobTitle == '')) { $this->jobTitleError = 'Job Title is required'; } elseif (strlen($this->jobTitle) > 30) { $this->jobTitleError = 'Job title is limited to 30 characters'; } elseif (!preg_match('/^[\\w\\- \\.]{2,30}$/', $this->jobTitle)) { $this->jobTitleError = 'Job Title can only include letters, hyphens & fullstops'; } if (strlen($this->bio > 200)) { $this->bioError = 'Bio is limited to 200 characters. You have ' . (strlen($this->bio) - 200); } elseif (!preg_match('/^[\\w\\s\\-\\.]{2,200}$/', $this->bio)) { $this->bioError = 'Bio can only include letters, hyphens & fullstops'; } // Make life easier $file = $_FILES['profile-image']; $imageName = $file['name']; // if the user has not provided an image // first brackets['source']second brackets['What field we want'] if ($imageName == '') { $this->profileImageError = 'Required'; } elseif ($this->firstNameError == '' && $this->lastNameError == '' && $this->jobTitleError == '' && $this->bioError == '') { // require the image upload class require 'vendor/ImageUploader.php'; // Instantiate the class $imageUploader = new ImageUploader(); // Mkae new filename based oon the staff members name $fileName = $this->firstName . '-' . $this->lastName; // Upload the image and make sure all went well $result = $imageUploader->upload('profile-image', 'img/staff/original/', $fileName); // If something went wrong if (!$result) { $this->profileImageError = $imageUploader->errorMessage; } else { $newImage = $imageUploader->getImageName(); $imageUploader->resizeImage('img/staff/original/' . $newImage, 320, 'img/staff/thumbnails/', $newImage); } // If there are no errors then insert a new staff member if ($this->profileImageError == '') { $result = $this->model->addNewStaff($newImage); // if success if ($result) { $this->staffSuccessMessage = 'Success'; } else { $this->staffErrorMessage = 'Something went wrong in the Database'; } } } }