I am trying to check if the form submit button is clicked so I tried:
if($request->input('submit')){
//do something
}
and tried:
$clicked=$request->input('submit');
if(isset($clicked)){
//do something
}
and also tried:
if($request->input('submit')!=null){
//do something
}
but when I do click the submit button in the form the execution of if-inside never happens so what is the right way to check if submit button clicked in laravel?
Check if the value of submit button is set. This might be the easiest also, I always use it.
HTML:
<button type="submit" name="find" value="Find">Find</button>
LARAVEL:
if (isset($request->find))
{
//code
}
this can be solved two ways: first way if your form contains just one button and your form is using POST then like Adnan Mumtaz said we can use :
if($request->method() == 'POST'){
//ur code here
}
but if the form contains multiple buttons and we want check if button than have name btn1 clicked then we can use:
if($request->has('btn1')){
//rest of the code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With