我需要一些帮助来弄清楚如何将日期输入字段更改为12小时格式,以便将变量传递给电子邮件发送脚本。我试图能够拥有一个在线时间表,以便员工可以在线输入时间。问题是我需要12小时制的时间,这样会计才能更好地阅读时间并更快地输入时间。我是PHP的新手,希望对您有所帮助。如有任何问题,请发表评论。
这是发送电子邮件时的样子:
HTML:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>TimeSheet</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="content">
<form class="timesheetform" action="form.php" method="post">
<p class="header">GRADY ELECTRIC<br>TIME SHEET</p>
<input type="text" name="employee" placeholder="Employee Name">
<input type="text" name="email" placeholder="Email">
<input type="number" name="job#" placeholder="Job # (see work order log)">
<p class="mini-heading">Date:</p>
<input class="across" type="date" name="date">
<p class="sub-heading">Start Time:</p>
<input class="across" type="time" name="starttime" placeholder="Start Time">
<p class="sub-heading">Lunch Duration:</p>
<input type="number" name="lunch" placeholder="(Enter In Minutes)">
<p class="sub-heading across">Stop Time:</p>
<input class="across" type="time" name="stoptime" placeholder="Stop Time">
<p class="sub-heading">Total Hours:</p>
<input type="text" name="totalhours" placeholder="Total Hours">
<p class="sub-heading">Drive Time:</p>
<input type="text" name="drivetime" placeholder="Drive Time">
<p class="sub-heading">Job Complete?</p>
<div class="radiobuttons">
<div class="radiobtnoption">
<p>Yes</p>
<input type="radio" name="radiobtn" value="YES">
</div>
<div class="radiobtnoption">
<p>No</p>
<input type="radio" name="radiobtn" value="NO">
</div>
</div>
<input type="text" name="customer" placeholder="Customer (ex: Brascia)">
<input type="text" name="location" placeholder="Location/Address">
<textarea name="jobdescription" placeholder="Job Description"></textarea>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-1" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-1" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-1" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-1" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-2" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-2" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-2" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-2" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-3" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-3" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-3" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-3" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-4" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-4" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-4" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-4" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-5" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-5" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-5" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-5" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-6" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-6" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-6" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-6" placeholder="Total">
</div>
<div class="materialssection">
<input class="materialsinfo" type="text" name="m-7" placeholder="Materials:">
<input class="materialsinfo" type="text" name="q-7" placeholder="Qty:">
<input class="materialsinfo" type="text" name="e-7" placeholder="Each:">
<input class="materialsinfo" type="text" name="t-7" placeholder="Total">
</div>
<textarea name="notes" placeholder="Notes:"></textarea>
<button type="submit" name="submit">Submit</button>
</form>
</div>
</body>
</html>
PHP:
<?php
if (isset($_POST['submit'])) {
$email = $_POST['email'];
$to = "example@example.com, $email";
$subject = "New TimeSheet";
$name = $_POST['employee'];
$date = $_POST['date'];
$jobnum = $_POST['job#'];
$radio = $_POST['radiobtn'];
$customer = $_POST['customer'];
$address = $_POST['location'];
$jobdes = $_POST['jobdescription'];
$starttime = mktime($_POST['starttime']);
$lunchtime = $_POST['lunch'];
$stoptime = mktime($_POST['stoptime']);
$totalhours = $_POST['totalhours'];
$drivetime = $_POST['drivetime'];
$notes = $_POST['notes'];
$m1 = $_POST['m-1'];
$m2 = $_POST['m-2'];
$m3 = $_POST['m-3'];
$m4 = $_POST['m-4'];
$m5 = $_POST['m-5'];
$m6 = $_POST['m-6'];
$m7 = $_POST['m-7'];
$q1 = $_POST['q-1'];
$q2 = $_POST['q-2'];
$q3 = $_POST['q-3'];
$q4 = $_POST['q-4'];
$q5 = $_POST['q-5'];
$q6 = $_POST['q-6'];
$q7 = $_POST['q-7'];
$e1 = $_POST['e-1'];
$e2 = $_POST['e-2'];
$e3 = $_POST['e-3'];
$e4 = $_POST['e-4'];
$e5 = $_POST['e-5'];
$e6 = $_POST['e-6'];
$e7 = $_POST['e-7'];
$t1 = $_POST['t-1'];
$t2 = $_POST['t-2'];
$t3 = $_POST['t-3'];
$t4 = $_POST['t-4'];
$t5 = $_POST['t-5'];
$t6 = $_POST['t-6'];
$t7 = $_POST['t-7'];
$message = "<html><body>";
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: lightgrey;'><td><strong>Tech Name:</strong> </td><td>" .$name. "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Job #:</strong> </td><td>" .$jobnum. "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Date:</strong> </td><td>" . $date . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Start Time:</strong> </td><td>" . date("h:i:a", $starttime) . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Lunch Duration:</strong> </td><td>" . $lunchtime . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Stop Time:</strong> </td><td>" . date("h:i:a", $starttime) . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Total Hours:</strong> </td><td>" . $totalhours . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Drive Time:</strong> </td><td>" . $drivetime . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Job Complete:</strong> </td><td>" . $radio . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Customer:</strong> </td><td>" . $customer . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Location/Address:</strong> </td><td>" . $address . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Job Description:</strong> </td><td>" . $jobdes . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Notes:</strong> </td><td>" . $notes . "</td></tr>";
$message .= "<tr style='background: lightgrey;'><td><strong>Materials:</strong></td> <td><strong>Qty:</strong></td> <td><strong>Each:</strong></td> <td><strong>Total:</strong></td></tr>";
$message .= "<tr style='background: lightgrey;'><td>$m1</td><td>$q1</td><td>$e1</td><td>$t1</td>";
$message .= "<tr style='background: lightgrey;'><td>$m2</td><td>$q2</td><td>$e2</td><td>$t2</td>";
$message .= "<tr style='background: lightgrey;'><td>$m3</td><td>$q3</td><td>$e3</td><td>$t3</td>";
$message .= "<tr style='background: lightgrey;'><td>$m4</td><td>$q4</td><td>$e4</td><td>$t4</td>";
$message .= "<tr style='background: lightgrey;'><td>$m5</td><td>$q5</td><td>$e5</td><td>$t5</td>";
$message .= "<tr style='background: lightgrey;'><td>$m6</td><td>$q6</td><td>$e6</td><td>$t6</td>";
$message .= "<tr style='background: lightgrey;'><td>$m7</td><td>$q7</td><td>$e7</td><td>$t7</td>";
$message .= "</table>";
$message .= "</body></html>";
// Always set content-type when sending HTML email
$headers = "From: forms@gradyelectricforms.com\r\n";
$headers .= "Content-Type: text/html";
mail( $to, $subject, $message, $headers );
header("location: http://www.gradyelectricinc.com", true, 301 ); exit;
}
?>
答案 0 :(得分:0)
获取时间输入值e.g. 17:00:00
,然后使用strtotime()
函数将其转换为Unix时间戳。
$t = strtotime('17:00:00');
然后,您可以使用date()
函数格式化时间戳记值,例如05:00 am
。
echo date('h:i a', $t); // 05:00 am
有两点需要考虑:
time
输入字段,例如Safari。$startTime
值用作停止时间。