简体   繁体   中英

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('jamalferhan@gmail.com')->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.

根据我在代码中看到的内容,您只需要将name属性添加到输入type =“ checkbox”(复选框)中,以便可以看到它们在请求中传递了。

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

In controller

$getcheckboxdata = $request->hello;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM