Question
Write the code that processes the data entered by the user 1. Open the index.php file for this application and review the code. Note that
Write the code that processes the data entered by the user
1. Open the index.php file for this application and review the code. Note that it displays a starting invoice date thats one month before the current date and a starting due date thats two months after the current date. However, this code doesnt process the dates that are entered into the text boxes.
2. Open the date_tester.php file for this application and review the code. Note that this code uses an if statement to display an error message or a table of date and time data.
3. In the index.php file, add the code that uses the two dates that are entered into the text box controls to display a table of data that calculates dates and times and formats them like this:
Invoice date: Due date: Current date: Current time: Due date message:
July 11, 2014 October 11, 2014 August 11, 2014 4:40:16 pm
This invoice is due in 0 years, 1 months, and 29 days.
If the current date is after the due date, the due date message should be in this format:
Due date message: This invoice is 0 years, 2 months, and 25 days overdue.
4. Make sure the user enters both dates.
5. Allow the user to enter a date in any format that can be parsed by the constructor of the DateTime class. This includes all of the most common date formats.
6. Make sure the user enters dates in a valid date format. To do that, you can use a try/catch statement to catch an exception thats thrown if the constructor of the DateTime class cant parse the date. For a review of the try/catch state- ment, you can refer to chapter 4.
7. Make sure the user enters a due date thats later than the invoice date.
8. Test the application to make sure it works correctly.
index.php
//set default value
$message = '';
//get value from POST array
$action = filter_input(INPUT_POST, 'action');
if ($action === NULL) {
$action = 'start_app';
}
//process
switch ($action) {
case 'start_app':
// set default invoice date 1 month prior to current date
$interval = new DateInterval('P1M');
$default_date = new DateTime();
$default_date->sub($interval);
$invoice_date_s = $default_date->format('n/j/Y');
// set default due date 2 months after current date
$interval = new DateInterval('P2M');
$default_date = new DateTime();
$default_date->add($interval);
$due_date_s = $default_date->format('n/j/Y');
$message = 'Enter two dates and click on the Submit button.';
break;
case 'process_data':
$invoice_date_s = filter_input(INPUT_POST, 'invoice_date');
$due_date_s = filter_input(INPUT_POST, 'due_date');
// make sure the user enters both dates
// convert date strings to DateTime objects
// and use a try/catch to make sure the dates are valid
// make sure the due date is after the invoice date
// format both dates
$invoice_date_f = 'not implemented yet';
$due_date_f-='not implemented yet';
// get the current date and time and format it
$current_date_f = 'not implemented yet';
$current_time_f = 'not implemented yet';
// get the amount of time between the current date and the due date
// and format the due date message
$due_date_message = 'not implemented yet';
break;
}
include 'date_tester.php';
?>
date_tester.php
Date Tester
Message:
Invoice date: | |
Due date: | |
Current date: | |
Current time: | |
Due date message: |
Below is an example of the result.
After y competition, the image below is the result when the dates 5/13/2017 and 8/13/2017 are entered.
Date Tester Invoice Date: 5/13/2017 Due Date: 8/13/2017 Submit Message: Invoice date ue dai Current date Current time: Due date message: not implemented yet not implemented yet not implemented yet not implemented yet not implemented yet Date Tester Invoice Date: 5/13/2017 Due Date: 8/13/2017 Submit Message: Invoice date ue dai Current date Current time: Due date message: not implemented yet not implemented yet not implemented yet not implemented yet not implemented yetStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started