I have use Laravel 9 and in a blade I have form below:
<form id="create-offline-payment-form" action="{{route ('user.cart.pay')}}" method="post">
@csrf
<input type="hidden" value="{{$shop_id}}" id="shop-id" name="shop_id">
<button id="payment" type="submit" >پرداخت آفلاین</button>
</form>
the form submit to this method:
public function payCart(Request $request)
{
Transaction::create([
'seller_id' => Auth::id(),
'amount' => $this->cartSum(),
]);
return redirect()->route('user.cart.paid');
}
and in the another method by route above, will show a view to user :
route('user.cart.paid') go to method below:
public function paidCart()
{
return view('user.cart.paid');
}
my problem is when a user click several times on submit botton, multiple record gonna be built on Transaction table.
how can I prevent that?
thanks
CodePudding user response:
$('form#id').submit(function(){
$(this).find(':input[type=submit]').prop('disabled', true);
});
CodePudding user response:
You can simply disable submit button using css or js after form submission