用户发送信息时如何打印信息
当用户打开页面时,它显示一个表单,就像任何其他表单一样,当用户完成信息保存在数据库中,但同时我想在纸上打印该信息…
<form method="post" action="save.php">
<input name="name">
<!-- like 30 more inputs, i know is crazy -->
<button type="submit">Send</button>
</form>
<?php
if(isset($_POST['_token']) && $c->validToken()) {
// Get all inputs, re-validate, clean...etc
// Save info into the DB
// Done!
// Here is where I would like to collect all the infomarion
// and print it, send it to a printert...
header('Location: thankyou.php');
exit;
}
?>
我可以用PHP,也可以用jquery…是我在做梦还是这是可能的?
是的,有一个很好的打印机连接到"服务器"(这是什么问题?)…
不,我没有使用ajax ....
不,我从来没有使用PHP打印,因此这个问题....我使用Java,但用户总是看到打印机对话框窗口,在这种情况下,用户不需要看到那个。
有两个答案为我指出了正确的方向,谢谢,我不知道谁否决了这个问题,但显然必须是一个天才,发现这个问题无关或太愚蠢....
这是可能的,但取决于你如何打印信息(字体,纸张类型,文件格式…)。希望这个tut对你有帮助。
我一直在写这样的表单,我将有一个表单引用本身,如下所示:
<form action="?" method="post"></form>
action参数中的"?"表示"调用同一页面"。当您提交表单时,所有输入和表单元素,如<select>
和<textarea>
,具有"name"属性将被提交,"name"属性是数组中的$_POST键,"value"属性是值。像文本输入这样的元素不像单选按钮和复选框那样事先具有书面的value属性,但是浏览器知道将用户输入的值作为"value"属性提交。所以……这包括提交按钮<input type="submit" name="submit" value="Submit">
等元素。当表单发送给自己时,页面顶部会有一个条件符
if(isset($_POST['submit'])){ // the form has been submitted
// get all $_POST values from the form and do great stuff with them
// (send to an API like PayPal or similar)
// when you have done all that you need to you can evaluate the response
// from the API, do other stuff, etc. then if you want to,
// print to the page.
// I will pretend that I created another array from some of the $_POST values,
// since I don't want ALL $_POST values like check boxes or the submit button to appear on the page
// We'll call it $response (and it is an array of values)
echo "<p>Your form was successfully submitted. The following values have
been added to our database:</p>";
echo "<ul class='responseList'>";
foreach($response as $k=>$v){
echo "<li>". $k ."=". $v ."</li>";
}
echo "</ul>";
} else { // the form hasn't been submitted yet
// show the form (this can even be put into a function to be called as needed)
}
我希望这有意义。您应该能够从$_POST数组创建较小的数组,这样您就可以在页面上将数组键重命名为更有吸引力的内容。例如,您可以使用"firstName"作为输入字段中的名称参数,但您不想回叫firstName,而是将其清理为"First name "。
如果您通过AJAX发送数据,那么通过AJAX检索确认,当检索到正确的确认时,然后像这样调用打印方法
$(document).ready(function () { window.print(); });