laravel 5.5提交表格的甜蜜警报

时间:2017-10-24 10:32:17

标签: javascript php laravel

我有一张表格。单击提交按钮时我需要激活。如何在laravel刀片中做到这一点。

我的表格

<form  action="{{ route('backend.tasks-send-email.store') }}" method="POST">
    {{ csrf_field()}}
    <label for="propertyName">Email To</label>
    <input class="form-control" id="editteamName" name="teamName" type="text" id="teamName" required="true" value="" disabled>
    <label for="maker-content">Message</label>
    <textarea id="maker-content" name="emailContent" ></textarea>

<button type="submit" class="btn btn-primary" id="submit">button</button>
</form>

Javascipt代码

$(document).on('click', '[#submit]', function (e) {
  e.preventDefault();
  var data = $(this).serialize();
  swal({
      title: "Are you sure?",
      text: "Do you want to Send this email",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "Yes, send it!",
      cancelButtonText: "No, cancel pls!",
  }).then(function () {
     swal(
    'Success!',
    'Your email has been send.',
    'success'
  )
  });
  return false;
});

1 个答案:

答案 0 :(得分:4)

试试这个。在你的表格中添加id属性。 在你的javascript中,当具有此id属性的表单被提交时,甜蜜警报被激活。

<强>表格

<form  action="{{ route('backend.tasks-send-email.store') }}" method="POST" id="form">
    {{ csrf_field()}}
    <label for="propertyName">Email To</label>
    <input class="form-control" id="editteamName" name="teamName" type="text" id="teamName" required="true" value="" disabled>
    <label for="maker-content">Message</label>
    <textarea id="maker-content" name="emailContent" ></textarea>
</form>

<强>的javascript

$(document).on('submit', '[id^=form]', function (e) {
  e.preventDefault();
  var data = $(this).serialize();
  swal({
      title: "Are you sure?",
      text: "Do you want to Send this email",
      type: "warning",
      showCancelButton: true,
      confirmButtonText: "Yes, send it!",
      cancelButtonText: "No, cancel pls!",
  }).then(function () {
      $('#form').submit();
  });
  return false;
});