/Users/johnr/Desktop/IA pdf Downloads/_New Projects Downloads May 7th/CS_IA_Mattew/storeCustomerInfo.html |
1 <?php 2 spl_autoload_register(function ($class_name) { // https://www.php.net/manual/en/language.oop5.autoload.php 3 include $class_name . '.class.php'; 4 }); 5 6 $firstName = $_POST['fname']; 7 if(isset($_POST['mname'])){ 8 $middleName = $_POST['mname']; 9 } 10 $lastName = $_POST['lname']; 11 12 //concatonating all the names into one string in order to do only one check for all the names 13 $name = $firstName.' '.$middleName.' '.$lastName; 14 //https://www.w3schools.com/php/php_form_url_email.asp 15 if (!preg_match("/^[a-zA-Z-' ]*$/",$name)) { 16 exit('<script>alert("Invalid Name, please try again"); history.back()</script>'); 17 } 18 19 //checking the email input (in addition to having the built in required attribute) 20 $email = $_POST["email"]; 21 $email = filter_var($email, FILTER_SANITIZE_EMAIL); 22 if(!filter_var($email, FILTER_VALIDATE_EMAIL)) { 23 exit('<script>alert("Invalid Email, please try again"); history.back()</script>'); 24 } 25 26 //taken from https://www.abstractapi.com/guides/php-validate-phone-number 27 //preg_match/^[0-9]{8,12}+$/ will check if all the characters are integers (between 0 and 9) and if there are between 8 and 12 characters 28 if(!preg_match('/^[0-9]{8,12}+$/', $_POST['phone'])) { 29 exit('<script>alert("Phone number must only contain numbers and be bewteen 8 to 12 digits"); history.back()</script>'); 30 } 31 32 //concatonating country code and phone number into one full phone number 33 $phoneNumber = "+".$_POST['countryCode'].$_POST['phone']; 34 35 $nationality = $_POST['nationality']; 36 37 //first or: departure minus the arrival date, if it equates to 0 days or a negative number (less than 1), it is invalid 38 //second or: checking if the current date is greater than (after) the departure date, meaing it is invalid 39 if((strtotime($_POST['departureDate']) - strtotime($_POST['arrivalDate'])) < 1 || (strtotime(date("Y-m-d")) > strtotime($_POST['arrivalDate']))){ 40 exit('<script>alert("Invalid dates, please try again"); history.back()</script>'); 41 } 42 43 $arrivalDate = $_POST['arrivalDate']; 44 $departureDate = $_POST['departureDate']; 45 $hotelStandard = $_POST['hotelStandard']; 46 $IPAddress = $_SERVER['REMOTE_ADDR']; 47 48 $rating = $_POST['hotelStandard']; 49 50 $customer = new Customer($firstName, $middleName, $lastName, $email, $phoneNumber, $nationality, $IPAddress); 51 $inquiry = new Inquiry(date("Y/m/d h:i:s"), $IPAddress, $arrivalDate, $departureDate, $rating,); 52 $inquiry->setCustomer($customer); 53 54 //storing the user-defined objects in the CPU to be persistant 55 apcu_store('customer', $customer); 56 apcu_store('inquiry', $inquiry); 57 58 //redirecting to the next page 59 header("Location: destinationpage.html"); 60 die(); 61