在 PHP ISSET 函数中使用 HTML 表单

发布于 2024-12-08 00:41:01 字数 875 浏览 0 评论 0原文

我有一个报价单,用户填写方框,单击提交,并且 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不念旧人 2024-12-15 00:41:01

您只需将 html 放在 IF 子句中即可。如果我正确理解你的问题..

    <?php  
    if (isset($_POST['submit']))
    {        
         $total = (int)$_POST['ssize'] + (int)$_POST['condition'] + (int)$_POST['opticalDrive'];
    ?>

    Price is : <?php echo $total;  ?>

    <form method="post" action="scriptforthisform.php">
    <fieldset>
    <legend></legend>
    First Name: <input type="text" name="fname" value=""/>
    Surname: <input type="text" name="sname" value="" />
    E-Mail Address: <input type="text" name="email" value=""/>
    House Number: <input type="text" name="HouseNo" value=""/>
    Street Name: <input type="text" name="Street" value=""/>
    Town/City: <input type="text" name="towncity" value=""/>
    Post Code: <input type="text" name="Postcode" value=""/>
    <input type="submit" value="send" name="submit_quote" />
    </fieldset>
    </form>

  <?php 
   } 
   ?>

You just place your html within the IF clause. If I understood correctly your question..

    <?php  
    if (isset($_POST['submit']))
    {        
         $total = (int)$_POST['ssize'] + (int)$_POST['condition'] + (int)$_POST['opticalDrive'];
    ?>

    Price is : <?php echo $total;  ?>

    <form method="post" action="scriptforthisform.php">
    <fieldset>
    <legend></legend>
    First Name: <input type="text" name="fname" value=""/>
    Surname: <input type="text" name="sname" value="" />
    E-Mail Address: <input type="text" name="email" value=""/>
    House Number: <input type="text" name="HouseNo" value=""/>
    Street Name: <input type="text" name="Street" value=""/>
    Town/City: <input type="text" name="towncity" value=""/>
    Post Code: <input type="text" name="Postcode" value=""/>
    <input type="submit" value="send" name="submit_quote" />
    </fieldset>
    </form>

  <?php 
   } 
   ?>
感情废物 2024-12-15 00:41:01

您的问题并不明确,但我认为您暗示页面提交给自身(我会包含一个空白的 action 属性,这样在这种情况下就不会产生歧义)。您可以执行以下操作:

<?php
    if (isset($_POST['submit'])) {
        $total = $_POST['ssize'] + $_POST['condition'] + $_POST['opticalDrive'];
        echo('Price is ' . $total . '<br>');
        // Include markup for your form here
?>
      <form method="post" action = "action.php">
         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" />
         <input type = 'submit' name = 'submit' value = 'Submit'/>
       </form>
    }
?>

另一种方法是在客户端计算总计,然后通过 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:

<?php
    if (isset($_POST['submit'])) {
        $total = $_POST['ssize'] + $_POST['condition'] + $_POST['opticalDrive'];
        echo('Price is ' . $total . '<br>');
        // Include markup for your form here
?>
      <form method="post" action = "action.php">
         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" />
         <input type = 'submit' name = 'submit' value = 'Submit'/>
       </form>
    }
?>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文