2013-02-06 55 views
1

問題:如何使HTML表單根據按鈕按下哪個按鈕來調用不同的PHP頁面?html表單 - 如何根據所選按鈕調用不同的php頁面

下面的代碼是我現在的解決方案,但我認爲必須有更好的方式來做到這一點,然後在頁面上創建多個表單?

<html> 
<body> 
    <form name="entry_form" action="entry_update_script.php" method="post" enctype="multipart/form-data"> 
     <input type="hidden" name="entry_id" value=""> 
     <input type="hidden" name="entry_item_id" value=""> 
     Truck/Railcar/Barge#:<input type="text" name="pro_number" value=""><br> 
     BOL #:<input type="text" name="bol" value=""><br> 
     <input type="submit" name="entry_submit" value="Add New Entry!"> 
    </form> 
    <form name="entry_form_add" action="entry_view.php" method="post" enctype="multipart/form-data"> 
     <input type="hidden" name="entry_id" value=""> 
     <input type="submit" name="submit" value="Add New Item!"> 
    </form> 
</body> 
</html> 

回答

4
<html> 
<body> 
    <script type="text/javascript"> 

    function submitAction(act) { 
     document.sample.action = act; 
     document.sample.submit(); 

    } 
    </script> 
    <form name ="sample" action="default.php"> 
     <input type="button" value = "blah1" onClick="submitAction('phpPage1.php')"> 
     <input type="button" value = "blah2" onClick="submitAction('phpPage2.php')"> 
    </form> 
</body> 
</html> 
+0

對不起,我看到你想使用按鈕生病了編輯真的很快 – 75inchpianist

+0

document.poop,呵呵? –

+0

哈哈雅,不要擔心,爲更成熟的觀衆改變它 – 75inchpianist

-2

您可以選擇的頁面從調度員去,這是一個可擴展的和可靠的解決方案:

表單

<form action="dispatcher.php" method="POST"> 
    <input type="radio" name="myOption" value="register" /> 
    <input type="radio" name="myOption" value="login" /> 
</form> 

dispatcher.php

$actions = array ('register', 'login'); 

// validate possible actions 
if (in_array($_POST['myOption']), $actions)) { 
    include ($_POST['myOption'] . '.php'); 
} 
相關問題