1

I'm trying to return the value of a checkbox within my laravel controller, but every time I request a input from a checkbox element in a form, it returns null.

My controller, retrieving the input of a element called Filter-Method.

Retrieving the input of a element called Filter-Method

Here I'm trying to request a input method called filter-method which is a checkbox.

My Route, since this function will execute on a button:

since this function will execute on a button

My Blade, where I'm trying to retrieve the result of my filter-method checkbox:

where im trying to retrieve the result of my filter-method checkbox

On line 38 I have a checkbox called filter-method, and when you click on the button on line 115 it should send a request to the controller where it would return a result but instead it returns null

The resulting image

Any ideas of why I'm returning null?

2
  • 5
    Add the code instead of images.Read stackoverflow.com/help/mcve Commented Apr 11, 2018 at 4:53
  • 3
    You need to use a form to send the checkbox value to server. Currently you are using <a> tag with your link that will not send any value to server. Commented Apr 11, 2018 at 5:00

4 Answers 4

2

You are not passing any parameter named filter-method. If you are posting values you should use post method.

Like following

Route::post('GetFilterByColumns','MentorController@FilterByValuesColoumns')

If you want to list data according to filter-method then try the following.

Route::get('GetFilterByColumns/{filter-method}','MentorController@FilterByValuesColoumns')

And in your mentorlist.blade.php page

change the href value according to route.

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

Comments

0

You have to add form to your blade around checkbox either with get or post method as per your requirement change route according to your form method

consider demo blade file

<form method="get" action="{{ url('GetFilterByColumns') }}" class="form-horizontal form-label-left"  id="">
   <div class="checkbox">
      <label><input type="checkbox" name="filter-method" value="filter-method>Method</label>
   </div>
   <input type="submit" value="submit"/>
</form>

Now you will get a checkbox value in contoller

Comments

0

This is very basic thing just use form instead of <a> tag. Every time you need to send input value to server you need to use <form> element. In image you have uploaded there is no <form> and you are using a <a> tag.

You need to do it like this

<form method="get" action="/getFilterBycolumns">
<input type="checkbox" name="filter-method">

// other input fields

// and then a submit button instead of <a>
<button class="your-class" type="submit"> Send</button>

Comments

0

just use POST instead of GET if you are sending form values

1 Comment

How does this improve on the earlier answer which has more detail?

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.