0

我有一个带有 2 个按钮的表单,它们具有来自产品 ID 的相同动态值。
我想要的是当您单击购物车按钮时,它发送到 cart.php,当您单击愿望按钮时,它发送到 wish.php

但是现在当我单击购物车按钮时,它会发送到 cart.phpwish.php,反之亦然。

有没有这样的表格,可以做我想要的?

<form id="form1" name="form1" method="post" >                   

<input type="hidden" name="pid"  value="<?php echo $id; ?>" />  
<input type="hidden" name="pidwish"  value="<?php echo $id; ?>" />  
<input type="SUBMIT" name="submit"  class="classname"  VALUE="add to cart" onClick="this.form.action='cart.php';this.form.submit()">

<input type="SUBMIT" name="submit"  class="classname"  VALUE="wishlist" onClick="this.form.action='memberSystem/wishes.php';this.form.submit()">

</form>
4

3 回答 3

0

请试试这个:

<form id="form1" name="form1" method="post" >                   
    <input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>" />  
    <input type="hidden" name="pidwish" id="pid_wish" value="<?php echo $id; ?>" />
    <input type="button" name="submit"  class="classname"  VALUE="add to cart" onClick="SubmitIt(1);">
    <input type="button" name="submit"  class="classname"  VALUE="wishlist" onClick="SubmitIt(2);">
</form>

并使用 Jquery 进行表单提交。

<script>
function SubmitIt(checkVal)
{
    var pid = $("#pid").value;
    var pid_wish = $("#pid_wish").value;
    if(checkVal == 1)
    {
        //submit your form for add cart
    }
    else
    {
        //submit your form for wish
    }
}
</script>
于 2012-10-26T19:24:25.870 回答
0

看到你传递的只是固定的隐藏值,有什么问题:

<form id="form1" name="form1" method="post" action="cart.php">                   
  <input type="hidden" name="pid"  value="<?php echo $id; ?>" />    
  <input type="SUBMIT" name="submit"  class="classname"  VALUE="add to cart">
</form>
<form id="form2" name="form1" method="post" action="memberSystem/wishes.php">                   
   <input type="hidden" name="pidwish"  value="<?php echo $id; ?>" />  
  <input type="SUBMIT" name="submit"  class="classname"  VALUE="wishlist">
</form>
于 2012-10-26T19:12:09.267 回答
0

请尝试它会工作

JavaScript:

function submitForm(actionPath)
{
  document.form1.action =actionPath;
  document.form1.submit();
}

HTML:

<form id="form1" name="form1" method="post" >                     
  <input type="hidden" name="pid"  value="<?php echo $id; ?>" />  
  <input type="hidden" name="pidwish"  value="<?php echo $id; ?>" />   
  <input type="SUBMIT" name="submit"  class="classname" VALUE="add to cart" onClick="submitForm('cart.php')">
  <input type="SUBMIT" name="submit"  class="classname" VALUE="wishlist" onClick="submitForm('memberSystem/wishes.php')">  
</form>
于 2012-10-26T19:20:09.793 回答