在 PHP ISSET 函数中使用 HTML 表单
我有一个报价单,用户填写方框,单击提交,并且 isset 函数可以在返回报价之前查看其是否已设置。
<?php
if (isset($_POST['submit'])) {
$total = $_POST['ssize'] + $_POST['condition'] + $_POST['opticalDrive'];
?> Price is <?php echo $total;
}
?>
此报价仅在单击提交按钮后出现。 如果用户希望接受报价,我还希望出现一个包含该报价的表格。但我不知道如何将 HTML 表单包含在该 PHP 中,因此使其与提交按钮一起出现。
这是我的表单的一个示例:
<form method="post">
First Name: <input type="text" name="fname" />
Surname: <input type="text" name="sname" />
E-Mail Address: <input type="text" name="email" />
House Number: <input type="text" name="HouseNo" />
Street Name: <input type="text" name="Street" />
Town/City: <input type="text" name="towncity" />
Post Code: <input type="text" name="Postcode" />
</form>
那么我如何将它们组合起来以同时出现在提交按钮之后?
I have a quotation form where the user fills out the boxes, clicks submit and the isset function works to see if its set before returning a quote.
<?php
if (isset($_POST['submit'])) {
$total = $_POST['ssize'] + $_POST['condition'] + $_POST['opticalDrive'];
?> Price is <?php echo $total;
}
?>
This quotation only appears after clicking the submit button.
If the user wishes to accept the quote i also want a form to appear with that quote. But i cant figure out how to include the HTML form in with that PHP so make it appear with it after the submit button.
This is an example of my form:
<form method="post">
First Name: <input type="text" name="fname" />
Surname: <input type="text" name="sname" />
E-Mail Address: <input type="text" name="email" />
House Number: <input type="text" name="HouseNo" />
Street Name: <input type="text" name="Street" />
Town/City: <input type="text" name="towncity" />
Post Code: <input type="text" name="Postcode" />
</form>
So how can I combine them both to appear at the same time after the submit button?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需将 html 放在 IF 子句中即可。如果我正确理解你的问题..
You just place your html within the IF clause. If I understood correctly your question..
您的问题并不明确,但我认为您暗示页面提交给自身(我会包含一个空白的
action
属性,这样在这种情况下就不会产生歧义)。您可以执行以下操作:另一种方法是在客户端计算总计,然后通过 JavaScript 将总计添加到表单中。这将要求访问者启用 JavaScript,这可能违反您的要求。
It's not explicit in your question, but I think you're implying that the page submits to itself (I would include a blank
action
attribute just so there's no ambiguity if this is the case). Here's something you can do:An alternative would be to have the total calculated client side and add the total in with the form from JavaScript. This would require the visitor to have JavaScript enabled, which may be against your requirements.