2011-10-03 24 views
2

我有一個引用表單,用戶填寫這些框,點擊提交併且isset函數在返回引用之前查看它是否設置。在PHP中使用HTML表單ISSET函數

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

此報價只點擊提交按鈕後會出現。 如果用戶希望接受報價,我還想要一個表單與該報價一起出現。但我無法弄清楚如何在該PHP中包含HTML表單,以便在提交按鈕後顯示它。

這是我的表格的一個例子:

<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> 

所以,我怎麼能結合他們兩個提交按鈕後,在同一時間出現?

回答

1

你只需將你的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 
    } 
    ?> 
+1

謝謝你們倆。這似乎已經解決了達米恩。 Thankyou –

1

這不是你的問題明確,但我覺得你暗示該頁面提交給自己(我將包括一個空白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,這可能違反了您的要求。

+0

沒問題,很樂意幫忙。 –