簡體   English   中英

如何從Laravel 5.4的表單中提取復選框信息?

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

我正在Laravel 5.4中的網站上工作,在該網站中我不確定如何從表單中提取復選框信息。

從我使用復選框信息的小提琴復制的HTML代碼是:

<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>


我正在使用的控制器代碼是:

   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!');

   } 


問題陳述:

我想知道我需要在控制器中進行哪些更改,以便能夠提取所有復選框信息。 目前,它僅從輸入字段中提取值。

根據我在代碼中看到的內容,您只需要將name屬性添加到輸入type =“ checkbox”(復選框)中,以便可以看到它們在請求中傳遞了。

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

在控制器中

$getcheckboxdata = $request->hello;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM