john
john

Reputation: 11679

How to pull checkbox information from the form in Laravel 5.4?

I am working on website in Laravel 5.4 in which I am not sure how to pull checkbox information from the form.

The HTML code copied from the fiddle from where I am using checkbox information is:

<div class ="form_check_attachments mt-4 ml-2">
   <div class="form-group  disney_posting_formchecks">
      <div class="form-check mb-3">
         <input class="form-check-input" type="checkbox" id="gridCheck">
         <label class="form-check-label" for="gridCheck">
         im interested in setting up a <span style="color:rgb(67, 67, 67);font-weight:bold;">pro</span>Store
         </label>
      </div>
      <div class="form-check mb-3">
         <input class="form-check-input" type="checkbox" id="gridCheck">
         <label class="form-check-label">
         I just want to post a thing or two on disney
         </label>
      </div>
      <div class="form-check mb-3">
         <input class="form-check-input" type="checkbox" id="gridCheck">
         <label class="form-check-label">
         I wanted to be notified when the app is live
         </label>
      </div>
   </div>
</div>


The controller code which I am using is:

   public function store(Request $request)
   {

/*
    dd($request->all());

  */   
      $this->validate($request, [
      'name' => 'required',
      'email' => 'required|email',
      'number' => 'required',
      'city' => 'required',
      'post' => 'required'
      ]);

      Mail::send('emails.posting-message', [
        'msg'=> "Name\t" . $request->name . "\r\n"
        . "Email\t" . $request->email . "\r\n"
        . "Number\t" . $request->number . "\r\n"
        . "City\t" . $request->city . "\r\n"
        . "Message\t" . $request->post . "\r\n"


       ], function($mail) use($request) {

          $mail->from($request->email, $request->name);

           $mail->to('[email protected]')->subject('Contact Message');
       });

       return redirect()->back()->with('flash_message', 'thank you, your posting info has been sent to our team. we will reach out as soon as we can to provide next steps!');

   } 


Problem Statement:

I am wondering what changes I need to make in the controller so that I am able to pull all the checkbox information. At this moment, it is pulling the values from the input fields only.

Upvotes: 0

Views: 71

Answers (2)

Sandip Jha
Sandip Jha

Reputation: 75

<label class="checkbox-inline">
    <input type="checkbox" name="hello" value="hello">Hello
</label>

In controller

$getcheckboxdata = $request->hello;

Upvotes: 0

latr.88
latr.88

Reputation: 859

From what I'm seeing in your code, you just need to add the name attribute to the input type="checkbox"(checkboxes) so you can see them passed in the request.

Upvotes: 2

Related Questions