我有 3 个不同的表格,我希望数据保留在我发送到的表格中,我该怎么做?
我发送了表单,但它计算了结果,但我必须再次单击我从导航栏发送的表单。
<div class="row">
<div class="col-lg-6 mx-auto">
<div class="card ">
<div class="card-header">
<div class="bg-white shadow-sm pt-4 pl-2 pr-2 pb-2">
<!-- Credit card form tabs -->
<ul role="tablist" class="nav bg-light nav-pills rounded nav-fill mb-3">
<li class="nav-item"> <a data-toggle="pill" href="#hes1" class="nav-link active show"> <i class="fas fa-credit-card mr-2"></i> Hesap1 </a> </li>
<li class="nav-item"> <a data-toggle="pill" href="#hes2" class="nav-link"> <i class="fab fa-paypal mr-2"></i> Hesap2 </a> </li>
<li class="nav-item"> <a data-toggle="pill" href="#hes3" class="nav-link"> <i class="fas fa-mobile-alt mr-2"></i> Hesap3 </a> </li>
</ul>
</div> <!-- End -->
<!-- Credit card form content -->
<div class="tab-content">
<!-- credit card info-->
<div id="hes1" class="tab-pane fade pt-3 active show">
<form action="#hes1" method="post">
<div class="form-group"> <label for="username">
<h6>Girilen Fiyat</h6>
</label> <input type="text" name="sayi1" placeholder="" value="<?php echo $_POST["sayi1"]; ?>" required="" class="form-control "> </div>
<div class="form-group"> <label for="cardNumber">
<h6>Kampanya Oranı</h6>
</label>
<div class="input-group"> <input type="text" name="sayi2" placeholder="" value="<?php echo $_POST["sayi2"]; ?>" class="form-control " required="">
<div class="input-group-append"> <span class="input-group-text text-muted"> <i class="fab fa-cc-visa mx-1"></i> <i class="fab fa-cc-mastercard mx-1"></i> <i class="fab fa-cc-amex mx-1"></i> </span> </div>
</div>
</div>
<div class="row">
<div class="col-sm-8">
<div class="form-group"> <label><span class="hidden-xs">
<h6>Kargo Oranı</h6>
</span></label>
<div class="input-group">
<select name="kargo" class="form-control">
<option value="26.99">26.99</option>
<option value="46.99">46.99</option>
<option value="49.99">49.99</option>
</select>
</div>
</div>
</div>
<div class="col-sm-4">
<div class="form-group mb-4"> <label data-toggle="tooltip" title="" data-original-title="Three digit CV code on the back of your card">
<h6>Hesap <i class="fa fa-question-circle d-inline"></i></h6>
</label>
<select name="secim" class="form-control">
<option value="+">Hesap</option>
</select> </div>
</div>
</div>
<div class="card-footer"> <button type="submit" name="kontrol" class="subscribe btn btn-primary btn-block shadow-sm"> Hesapla </button>
</div></form>
<div class="container">
<table class="table table-striped">
<?php
if(isset($_POST["kontrol"]))//kontrol adında bir form nesnesi var mı kontrolü yapılıyor
{
$sayi1=$_POST["sayi1"];
$sayi2=$_POST["sayi2"];
$sayi3=100;
$secim=$_POST["secim"];
$kargo=$_POST["kargo"];
$sonuc=0;
$sonuc2=0;
$sonuc3=0;
if($secim == '+')
{
$sonuc=$sayi1*$sayi2/$sayi3;
$sonuc3=$sayi1-$sonuc;
$sonuc2=$sayi1+$sayi2;
$sonuc4=$sonuc3*12/100;
$sonuc5=$sonuc3-$sonuc4;
}
echo "<h1 class='text-info'>Musterinin Alacagi=$sonuc3</h1>";
echo "<h1 class='text-info'>Komisyon=$sonuc4</h1>";
echo "<h1 class='text-info'>Kargo=$kargo</h1>";
echo "<h1 class='text-info'>Kazanc=$sonuc5</h1>";
echo "<h1 class='text-info'>KargosendenKazanc=$sonuc5</h1>";
}
?>
</table>
</div>
</div>
我有 3 个不同的表格,我希望数据保留在我发送到的表格中,我该怎么做?我发送了表单,但它计算了结果,但我必须再次单击我从导航栏发送的表单。
首先,您需要随每个表单一起发送一个参数,用于标识已发送的表单。例如
<input type="hidden" name="formname" value="hes1">
您似乎使用了 bootstrap,因此您必须控制在哪里显示 css 类“active”和“show”:
<div id="hes2" class="tab-pane fade pt-3
<?php if($_POST["formname"] == 'hes2') { ?> active show <?php } ?> ">
您必须在导航栏中的所有表单和所有选项卡上执行此操作。 此外,对于选择作为标准的表单和导航栏项目,您将必须使用改编的 if 子句来确保在不存在“formname”值的情况下也设置“active show”:
<div id="hes1" class="tab-pane fade pt-3
<?php if($_POST["formname"] == 'hes1' OR empty($_POST["formname"]) { ?> active show <?php } ?> ">