Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Instructions Create a two-part form that calculates an employee\'s weekly gross

ID: 3914500 • Letter: I

Question

Instructions

Create a two-part form that calculates an employee's weekly gross salary, based on the number of hours worked and an hourly wage that they choose. Use an HTML5 document named paycheck.html as a web form with three text boxes - one for name, one for number of hours worked, and one for hourly wage. Use a PHP document named paycheck.php as the form handler. Compute any hours over 40 as time-and-a half. Be sure to verify and validate the submitted form and provide appropriate error messages for invalid values. Format results to 2 decimal places.

Clocalhost/pay/Paycheck.html Paycheck Data Name (first and last): Hours Worked: Hourly Wage: S Clear Form Send Form

Explanation / Answer

///////////////////////////////////////////////////////////////////////////////////////////

<html>

<body>

<h1>Paycheck Data</h1>

<form name="paycheck" action="paycheck.php" method="post">

Name (first and last): <input type="text" name="name" /><br /><br />

Hours Worked: <input type="text" name="Hours" /><br /><br />

Hourly Wage: $ <input type="text" name="Wage" /><br /><br />

<input type="reset" value="Clear Form" />&nbsp;&nbsp;<input type="submit" name="Submit" value="Send Form" />

</body>

</html>

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

<?php

$hoursWorked = validateInput ($_POST['Hours'], "Hours");

$wages = validateInput($_POST['Wage'], "Wage");

  

if ($errorCount>0) {

echo "Please enter the information.<br /> ";

redisplayForm($hoursWorked, $wages);

}

if (is_numeric($hoursWorked) && is_numeric($wages)){

if ($hoursWorked <= 40)

{

$payCheck = ($hoursWorked * $wages);

echo "<h1>Process Paycheck Data</h1><p><strong>$hoursWorked</strong> hours @<strong>$$wages</strong>/hr = <strong>$$payCheck</strong></h1><br /><p><a href="Paycheck.html">Create another paycheck</a></p>";

}

if ($hoursWorked > 40)

{

$payCheck = (40 * $wages) + (($hoursWorked - 40) * $wages * 1.5);

$temp3=40*$wages;

$temp=$hoursWorked -40;

$temp1=$wages*1.5;

$temp2=(($hoursWorked - 40) * $wages * 1.5);

echo "<h1>Process Paycheck Data</h1><p><strong>40</strong> hours @<strong>$$wages</strong>/hr = <strong>$temp3</strong></h1><p>$temp hours @$temp1/hr = $temp2</p>";

echo "your total for $hoursWorked hours is $payCheck";

echo "<br /><p><a href="Paycheck.html">Create another paycheck</a></p>";

}

}

else{

echo "<p>Only numbers can be used. Press the back button to try again.</p>";

//displayrequired($fieldName);

//(is_string($hoursWorked) && is_numeric($wages)==0)

//redisplayForm($hourWorked, $wages);

}

function displayRequired($fieldName) {

echo "The field "$fieldName" is required to calculate the wages earned.<br /> ";

}

function validateInput($data, $fieldName) {

global $errorCount;

if (empty($data)) {

displayRequired($fieldName);

++$errorCount;

$retval = "";

}

else{

return ($data);

}

}

$errorCount=0;

function redisplayForm($hoursWorked, $wages) {

?>

<form name="paycheck" action="process_Paycheck.php" method="post">

<p>Number of Hours Worked: <input type="text" name="Hours" value="<?php echo $hoursWorked; ?>" /><br />

Hourly Wage: <input type="text" name="Wage" value="<?php echo $wages; ?>"/><br />

<input type="reset" value="Clear Form" />&nbsp;&nbsp;<input type="submit" name="Submit" value="Send Form" />

</form>

<?php

}

?>

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////