dongzongxun8491 2011-11-28 18:00
浏览 108
已采纳

如何处理表单中的两个提交按钮?

I don't understand this,

if I do this and I click the check out button, the page won't go to the check out page,

<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="checkout" id="checkout" type="submit" value="Check out">Check out</button>
</form>

It only does if I change the name="checkout" to name="cart-checkout",

<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="cart-checkout" id="checkout" type="submit" value="Check out">Check out</button>
</form>

It works that way but does not make any sense to me, do you know why it does it that way?

So I tried to use <a> tag inside the <button> tag and it goes to the check out page,

<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="checkout" id="checkout" type="submit" value="Check out"><a href="checkout.php">Check out</a></button>
</form>

But does it a valid html to put <a> tag inside the <button> tag?

  • 写回答

3条回答 默认 最新

  • dongwen6743 2011-11-28 18:05
    关注

    Why not change the buttons to:

    <input name="update" id="update" type="submit" value="Update cart">
    <input name="cart-checkout" id="checkout" type="submit" value="Check out">
    

    Then in PHP (on cart.php) you can do:

    <?php
      if($_POST){
         if(isset($_POST['update']){
           // process update
         } else if(isset($_POST['cart-checkout']){
           // process cart checkout
           // or uncomment the below line to forward to checkout.php
           // header("Location: checkout.php");
         }
      }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号