M
M
Mesuti2018-04-30 16:30:22
JavaScript
Mesuti, 2018-04-30 16:30:22

Auto-close alert in Bootstrap 3?

Hey!
There is a feedback form with two alerts about the successful sending of a letter or an error.
How can I make this alert auto-close after a certain time?
The difficulty is that they are formed in php when sending a letter.
Is it possible to write the solution directly in the php file, or is there a js script for auto-closing alerts if they appear on the page?
Here is the code:

$result = '';
  if (mail ($to, $subject, $body, $headers)) {
    $result .= '<div class="alert alert-success alert-dismissible" role="alert">';
 		$result .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
    $result .= 'УСПЕШНО ОТПРАВЛЕНО!';
    $result .= '</div>';

    echo $result;
    die();
  }

  $result = '';
  $result .= '<div class="alert alert-danger alert-dismissible" role="alert">';
  $result .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
  $result .= 'ОШИБКА ОТПРАВКИ';
  $result .= '</div>';

  echo $result;

I found one example of auto-closing, but I can't adapt it to my code.
https://codepen.io/CSWApps/pen/XJoLmN

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2018-04-30
@webinar

why write a bicycle?
alertifyjs.com/notifier.html

P
profesor08, 2018-04-30
@profesor08

Use https://ned.im/noty/#/
Customize how you want. As a result, you will get what you need.
Or insert a timeout and call the code.

$(".alert").fadeOut();
$(".alert").slideUp();
$(".alert").hide();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question