Hi guys,
I am taking a PHP class and I need your help. I have the instructions below:
1. Create a variable called $validations that stores an empty array.
2. For each data field’s input, make a call to the appropriate validation function for the field and store the result an new index in the $validations array.
3. Create a variable called $errors that stores an empty
array.
4.Write a foreach loop for the $validations array. With each iteration, check if the index is empty. If the index is not empty, add the value as a new index of the $errors array.
5. Otherwise, if the form has not been submitted, write statements for th
e following:
6. Initialize a variable for each form input with a value of an empty string.
Example: $first_name = '';
I have written the code, but I am not sure if I got it right, this is the code:
$validations = array(); $validatfirst_name = required($first_name, $min , "First Name" ); $validatlast_name = required($last_name, $min , "Last Name" ); $validatemail = valid_email($email, "Email Address"); $validatephone_num = valid_int($phone_num, $min, "Phone"); $validatephone_num2 = valid_int($phone_num2, $min, "Phone"); $validatephone_num3 = valid_int($phone_num3, $min, "Phone"); $validatmessage = required($message, '1', message); $validations = array($validatfirst_name, $validatlast_name, $validatemail, $validatephone_num, $validatephone_num2, $validatephone_num3, $validatmessage); $errors = array(); foreach($validations as $index=>$validation) { if(!empty($index)) { $errors[$index] = $validation; } } if(!isset($_POST['submit'])) { $first_name = ''; $last_name = ''; $email = ''; $phone_num = ''; $phone_num1 = ''; $phone_num2 = ''; $phone = ''; $message = ''; }