2014-08-29 65 views
0

productdetail.php多個按鈕

<form method="post" action="cart.php"> 
    --data is to kept in session -- 
    <input type="hidden" name="type" value="add" /> 
    <button class="">ADD TO CART</button> 
    <button class="">BUY NOW</button> 
    </from> 

ONCLICK 加入購物車它應該重定向到

--> cart.php --> productdetail.php 

ONCLICK 現在購買它應該重定向到

-->cart.php-->purchasing page(viewcart.php) 

我應該如何處理它們在cart.php

FOR加入購物車:它應該去cart.php然後productdetail.php FOR立即購買:cart.php-> viewcart.php

+2

什麼是真正的你的問題???無法理解.. – Lal 2014-08-29 18:40:51

+0

是購物車網站 上productdetail.php我們有兩個按鈕 「加入購物車」和「立即購買」 車(名稱,價格,數量)在cart.php 中處理點擊:添加到購物車= - > cart.php - > productdetail.php 點擊:現在購買= - > cart.php - >購買頁面(視圖。 php) 如何處理這兩個動作,並重定向到基於點擊按鈕的頁面 – dinu1389 2014-08-29 18:42:46

+0

你可以在HTML表單中添加任意數量的按鈕,但只能有一個提交按鈕..在這裏你沒有任何提交按鈕.. – Lal 2014-08-29 18:44:06

回答

0

您應該處理cart.php上的重定向。要知道這是點擊,您就可以根據被點擊您的按鈕做了JS填充隱藏輸入:

<form method="post" action="cart.php" id="someFormId"> <!-- I added id to form --> 
    <!-- your other form inputs and etc here --> 


    <!-- I added a new input hidden --> 
    <input type="hidden" name="userAction" id="inputUserAction" value="" /> 

    <!-- I added type, class and data to both buttons --> 
    <button class="formButton" data-user-action="add" type="button">ADD TO CART</button> 
    <button class="formButton" data-user-action="buy" type="button">BUY NOW</button> 
</form> 

考慮你使用jQuery,添加一個點擊監聽器:

$(function(){ //this is shorthand for document.ready 
    $('.formButton').on('click',function(){ 
     $('#inputUserAction').val($(this).data('userAction')); //update our hidden with the data 
     $('#someFormId').submit(); //submit the form 
    }); 
}); 

現在您將在您的cart.php上收到$_POST['userAction'],您可以根據「添加」或「購買」來完成您的ifs並重定向至您的喜好。

0

這是你想要的嗎?

<form method="post" action="cart.php"> 
    --data is to kept in session -- 
    <input type="hidden" name="type" value="add" /> 
    <button class="cartbutton">ADD TO CART</button> 
    <button class="buynowbutton">Buy Now</button> 
</from> 
+0

我應該如何處理它們cart.php 要加入購物車:它應該去cart.php,然後productdetail.php 現在購買:cart.php ---> viewcart.php – dinu1389 2014-08-29 18:48:21

+0

'' – TerryG 2014-08-29 18:51:39

+0

cart.php正在處理所有數據,如名稱,價格,數量和存儲在會話中。點擊現在購買它應該去cart.php,然後viewcart.php – dinu1389 2014-08-29 18:53:24

2
<form method="post" action="cart.php" id="someFormId"> <!-- I added id to form --> 
    <!-- your other form inputs and etc here --> 


    <!-- I added a new input hidden --> 
    <input type="hidden" name="userAction" id="inputUserAction" value="" /> 

    <!-- I added type, class and data to both buttons --> 
    <button class="formButton" data-user-action="add" type="button">ADD TO CART</button> 
    <button class="formButton" data-user-action="buy" type="button">BUY NOW</button> 
</form> 

$(function(){ //this is shorthand for document.ready 
    $('.formButton').on('click',function(){ 
     $('#inputUserAction').val($(this).data('userAction')); //update our hidden with the data 
     $('#someFormId').submit(); //submit the form 
    }); 
});