Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel Form Request = if button was clicked

Tags:

php

laravel

I need to know which button was clicked inside a request form on laravel since i have Save and Update buttons.

App\Http\Requests\RegistrationRequest.php

public function rules()
{
    $myrule = [ 'name' => 'required', 'age' => 'required' ];

    if (isset($_POST['save']))
    {
        $myrule['application_form'] = 'required';
    }
    elseif (isset($_POST['update']))
    {
        $myrule['application_form'] = 'required_without:is_application_form';
    }

    return $myrule;
}

i need to know if the button that was click is Save or Update because I'm requiring for the application_form file field to be required if the Save button is clicked but I only require the application_form field if the is_application_form hidden field is empty.

the setup above is working for name and age field but ignores the codes inside the IF conditions.

like image 952
kapitan Avatar asked Mar 07 '23 16:03

kapitan


1 Answers

In html

<button type="submit" name = "submit" value = "Save"></button>
<button type="submit" name = "submit" value = "Update"></button>

In code

if($request->submit == "Save")
{
......
}
else if($request->submit == "Update")
{
.....
}
like image 104
Rajob Raihan Monmoy Avatar answered Mar 19 '23 00:03

Rajob Raihan Monmoy