我有以下 HTML:
<form method="post" id="print" action="writefile.php" onsubmit="Javascript:window.print(); return true;">
<div id="non-printable">
Enter First & Last Name:
<input id="who" name="who" type="text" /><br><br>
Enter Taken Date:
<input id="tdate" readonly name="todays_date" onfocus="showCalendarControl(this);" type="text" /><br><br>
<input id="submit" type="button" class="btn" value="Submit" />
<div id="printout" style="text-align:center;display:none;">
<input type=submit value="Print Certificate" />
</div>
</div>
</form>
<div id="parent">
<h1>THIS WILL PRINT WHEN 'PRINT CERTIFICATE' IS PRESSED</h1>
</div>
下面的 CSS:
@media print {
#non-printable { display: none; }
#parent { display: block; }
}
我想要做的是,当按下 PRINT CERTIFICATE 时,我想写入位于我的服务器中的文件,并显示当前正在执行的打印窗口。我怎样才能做到这一点?
我知道我可以使用以下 PHP,但合并是问题所在:
<?php
session_start();
// Clean up the input values
foreach($_POST as $key => $value) {
$_POST[$key] = stripslashes($_POST[$key]);
$_POST[$key] = htmlspecialchars(strip_tags($_POST[$key]));
}
$printfor = $_POST['who'];
$dte = $_POST['todays_date'];
$filename = "writefile.txt"; #Must CHMOD to 666, set folder to 777
if($printfor && $dte) {
$text = "\n" . str_pad($_SESSION['printlogin'], 15) . "" . str_pad($printfor, 30) . "" . str_pad($dte, 15);
$fp = fopen ($filename, "a"); # a = append to the file. w = write to the file (create new if doesn't exist)
if ($fp) {
fwrite ($fp, $text);
fclose ($fp);
#echo ("File written");
}
else {
#echo ("File was not written");
}
}
?>
附加到文件: