0

I am having the following form, which I would like to submit to my backend.

<form id="revisionFilter" action="{{ route('revision.filter') }}" method='POST'>
  <input class="form-check-input" type="checkbox" value="" id="checkbox1">
  <label class="form-check-label" for="checkbox1">
                                    1
                                </label>
  <input class="form-check-input" type="checkbox" value="" id="checkbox0">
  <label class="form-check-label" for="checkbox0">
                                    0
                                </label>
  <label class="form-check-label" for="checkboxNull">
                                <input class="form-check-input" type="checkbox" value="" id="defaultCheck1">
                                <label class="form-check-label" for="checkboxNull">
                                    Null
                                </label>
  <input type="hidden" name='_method' value='POST'>
  <input id="revisionFilterSubmit" type="submit" class='btn btn-danger btn-sm' value='Filter'>
</form>

My backend looks like the following:

routes:

Route::post('/revision/filter', 'RevisionController@filter')->name('revision.filter');

RevisionController:

public function filter(Request $request)
{
    Log::info("Request: ");
    Log::info($request);

    return redirect()->route('revision.rindex');
}

My problem is that when I press the button I am getting redirected to:

The page has expired due to inactivity. 

Please refresh and try again.

Instead I would like to see the request with the values of the checkboxes to implement the db saving functionality.

I appreciate your replies!

2
  • 1
    add a CSRF field in your form using {{ csrf_field() }} Commented Jan 5, 2018 at 8:04
  • @Wreigh Thx for your answer! The request I get looks the following: array ( '_token' => '0l3rUUfpQGxnOX9Jpim9vEXQEkCFP7nqsQiSfhwh', '_method' => 'POST', ) Any suggestions how to get the checkbox values? Commented Jan 5, 2018 at 8:08

2 Answers 2

2

since I've already made a comment. I will put my answer in the answer box lol.

To answer you, you're not getting any checkbox value since you're checkboxes don't have any name attribute.

You need to put a name attribute to them. E.g.,

<input class="form-check-input" type="checkbox" value="" name="checkbox0" id="checkbox0">

From there, you should now be able to see the value of the checkbox via its name.

Sign up to request clarification or add additional context in comments.

Comments

0

Just put same name to your checkbox.For example

 <input class="form-check-input" type="checkbox" value="" id="checkbox1" name="revisionFilter">
 <input class="form-check-input" type="checkbox" value="" id="checkbox2" name="revisionFilter">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.