如何在laravel中执行函数后显示弹出模式?

时间:2017-11-02 02:20:44

标签: php laravel email bootstrap-modal

嘿伙计们,所以我做了一个简单的联系表格来发送电子邮件。当我按下电子邮件发送的发送按钮时,如何显示模态或通知?但它必须首先执行电子邮件发送功能,然后才显示模态。

刀片:



<form role="form" enctype="multipart/form-data" action="{{action('AltHr\Portal\PortalController@sendemail')}}" method="post" class="m-t-15">
{{csrf_field()}}
  <div class="form-group form-group-default">
    <label>Full Name<span style="color:red">*</span></label>
    <input type="text" name="name" placeholder="As per IC" class="form-control" required>
  </div>
  <div class="form-group form-group-default">
    <label>Company<span style="color:red">*</span></label>
    <input type="text" name="company" placeholder="Company name" class="form-control" required>
  </div>
  <div class="form-group form-group-default">
    <label>Email<span style="color:red">*</span></label>
    <input type="email" name="email" placeholder="Company email preferred" class="form-control" required>
  </div>
  <div class="form-group form-group-default">
    <label>Phone Number</label>
    <input type="number" name="number" placeholder="Phone number optional" class="form-control">
  </div>
      <div class="form-group form-group-default">
                  <label>Category</label>
                  <select name="category" class="full-width form-control">
                    <option value="General">General</option>
      <option value="Sign Up">Sign Up</option>
      <option value="Onboarding">Onboarding</option>
      <option value="Expenses">Expenses</option>
      <option value="Travels">Travels</option>
      <option value="Leaves">Leaves</option>
      <option value="Suggestions">Suggestions</option>
                  </select>
              </div>
  <div class="form-group form-group-default">
    <label>Message<span style="color:red">*</span></label>
    <textarea name="text" placeholder="Please type your message here" style="height:100px" class="form-control" required></textarea>
  </div>
  <div class="form-group form-group-default">
    <label>Attachment</label>
    <input type="file" name="files[]" accept="file_extension|image/*|media_type" multiple>
  </div>

  <div class="sm-p-t-10 clearfix">
    <i class="pull-left small hint-text m-t-5 font-arial"><span style="color:red">*</span>indicates required field</i>
    <button class="btn btn-primary font-montserrat all-caps fs-12 pull-right xs-pull-left">Submit</button>
  </div>
  <div class="clearfix"></div>
</form>
&#13;
&#13;
&#13;

路线:

&#13;
&#13;
	Route::post('send-email','PortalController@sendemail');
&#13;
&#13;
&#13;

控制器:

&#13;
&#13;
public function sendemail(Request $request)
	{
		$data = array(
			'name'=> $request->name,
	        'email'=> $request->email,
	        'text'=> $request->text,
	        'category'=> $request->category,
	        'company'=> $request->company,
	        'number'=> $request->number
    	);

    	$files = $request->file('files');

	    \Mail::send('AltHr/Portal/supportemail', $data, function ($message) use($data, $files){

	        $message->from($data['email'], $data['name']);
	        $message->to('ra7veer@gmail.com')->subject($data['company'] . ' - ' .$data['category']);

	        if(count($files > 0)) {
	            foreach($files as $file) {
	                $message->attach($file->getRealPath(), array(
	                    'as' => $file->getClientOriginalName(), // If you want you can chnage original name to custom name      
	                    'mime' => $file->getMimeType())
	                );
	            }
	        }


	    });

	    \Mail::send('AltHr/Portal/supportresponse', $data, function ($message) use($data){

	        $message->from('ra7veer@gmail.com', 'alt.hr Support');
	        $message->to($data['email'])->subject('Greetings from alt.hr');

	    });
	    
		return view('AltHr.Portal.support');
	}
&#13;
&#13;
&#13;

代码工作正常现在我只需要一个模态来表示电子邮件已发送出去。我怎么能这样做?

模态:

&#13;
&#13;
<div id="emailSentModal" class="modal fade" role="dialog">
    <div class="modal-dialog">

      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Some text in the modal.</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>

    </div>
  </div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

您可以通过使用Ajax,使用它发送POST请求,并在获得响应后在Javascript中显示模式来实现。

类似于:

    $.ajax({
       type: "POST",
       url: {{action('AltHr\Portal\PortalController@sendemail')}},
       data: {
           // Your data here
       },
       success: function(msg)
       {
           $("#emailSentModal").modal("toggle");
       }
    });

答案 1 :(得分:0)

您可以使用会话变量。如果此会话变量具有值,则模式将显示。像这样的东西。

控制器

public function sendemail(Request $request)
      .....
      ...
      return view('AltHr.Portal.support')->with('modal','true');

刀片

  <script>
            @if(session()->has('modal'))
             $("#emailSentModal").modal("toggle");

            @endif
        </script>