Kenneth
Kenneth

Reputation: 2993

laravel 5.5 Sweet alert in submiting form

I have a form. I need to activate when click the submit button. how can id do this in laravel blade.

my form

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

$(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;
});

Upvotes: 2

Views: 5295

Answers (1)

K Developer
K Developer

Reputation: 56

Try this one. in you're form add id attribute. in your javascript when form with this id attribute is submit the sweet alert is activated.

Form

<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;
});

Upvotes: 4

Related Questions