recovery men recovery men - 1 year ago 111
PHP Question

How get id off button in laravel controller laravel 5.3

Here i have buttons like this

<button type="submit" name="submit_1" class="btn green" value="submit_1">Save & Add Another</button>
<button type="submit" name="submit_1" class="btn green" value="submit_2">Save & Exit</button>

in my controller i redirect pages on button click i cannot change name of buttons because i am using in update function to redirect with submit_1
now what should do i also can use id maybe for this but dont know how to use it

if(Input::get('submit_1')) {
return redirect()->route('data.create');
} elseif(Input::get('')) {
return redirect()->route('data.index');

Its always redirect to create page but i want if i click button2 which is Save & Exit it should be redirect to index page.
what should i do to to differentiate between buttons except changing name of buttons.. if any method with id please help me and guide to best

Answer Source

You need to compare the input with a value.

At the minute your basically just saying if('submit_1') (or 'submit_2') either will evaluate to being true, you're not actually checking the the value for submit_1 is actually 'submit_1'.

(I think the confusion comes from having the value of one of your buttons being the same as the name of your buttons )

Change your if condition to be:

if(Input::get('submit_1') == 'submit_1')

Hope this helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download