如果单击另一个按钮后显示为空白,如何从textfield获取值?

时间:2018-03-19 03:18:14

标签: php html post textinput

单击“订单”后价格显示没有问题。提交按钮    但是一旦我点击“付款”,就无法获得价格的价值。按钮。    我怎样才能从文本字段中获取值而不会丢失    单击该值。或者如果可能的话,可以保存它。     form sample

<?php
if(!empty($_POST['myorder'])){

    $order=trim($_POST['myorder']);

    if($order=="wintermelon"){
    $price = 100 * $_POST['qty'] ;

    if($order=="taro"){
    $price = 110 * $_POST['qty'] ;

    }
    if($order=="caramel"){
    $price = 110 * $_POST['qty'] ;

}


}
}

if(isset($_POST['pay'])){

    **$price=trim($_POST['price']);**

    if(!empty($_POST['cash']) ){

    $cash=trim($_POST['cash']);

    if($cash >= $price){
        $change = $cash - $price;
    }
    if($cash < $price){

        $insuf = "<span style='font-size: 15px;'>*You have insufficient 
cash.</span>";
    }
}else{
    $errorMessage= "<span style='font-size: 15px;'>*Please insert cash.
</span>";
}

}
?>

//HTML code:

<form method="post" action="<?php echo 
htmlspecialchars($_SERVER["PHP_SELF"]);?>" id="my form">
<h3 style="color: #FFF;">Order</h3>
<div class="form-row">
    <div class="form-group col-md-4">
    <input type="text" name="placeorder" id="placeorder" class="form-
control" value="<?php echo htmlentities($order)?>" disabled>


    </div>
        <div class="form-group col-md-4">
        <label for="mango"><font color="white">Quantity</font></label>
        <input type="number" class="col-xs-2" name="qty" id="qty1" min="1" 
max="10" value="" >


</div>
</div>
<h5 style="color: #FFF;">Price</h5>
<div class="form-row">
<div class="form-group col-md-4">
<input type="text" name="price" class="form-control" value='<?php echo htmlentities($price)?>' disabled>
</div>
<div class="form-group col-md-4">

<input type="submit" name="addorder" class="btn btn-primary"  value="Order">
</div>
</div>
<h3 style="color: #FFF;">Order</h3>
<div class="form-row">
    <div class="form-group col-md-4">
    <input type="text" name="placeorder" id="placeorder" class="form-
control" value="<?php echo htmlentities($order)?>" disabled>


    </div>
        <div class="form-group col-md-4">
        <label for="mango"><font color="white">Quantity</font></label>
        <input type="number" class="col-xs-2" name="qty" id="qty1" min="1" 
max="10" value="" >


</div>
</div>
<h5 style="color: #FFF;">Price</h5>
<div class="form-row">
<div class="form-group col-md-4">
<input type="text" name="price" class="form-control" value='<?php echo 
htmlentities($price)?>' disabled>
</div>
<div class="form-group col-md-4">

<input type="submit" name="addorder" class="btn btn-primary"  value="Order">
</div>
</div>

<h5 style="color: #FFF;">Cash</h5>
<div class="form-row">
<div class="form-group col-md-4">
<input type="text" name="cash" class="form-control" <?php echo 
htmlentities($cash)?>>
<?php echo $insuf ?>
<?php echo $errorMessage ?>
</div>
<div class="form-group col-md-4">
**<input type="submit" name="pay" class="btn btn-primary" value="Pay">**
</div>
</form>

0 个答案:

没有答案