Skip to content

Instantly share code, notes, and snippets.

@rpmahoney
Created November 15, 2016 02:56
Show Gist options
  • Select an option

  • Save rpmahoney/7bf3e7c901b77ea7129ed0846b399929 to your computer and use it in GitHub Desktop.

Select an option

Save rpmahoney/7bf3e7c901b77ea7129ed0846b399929 to your computer and use it in GitHub Desktop.
PHP functions to create Bootstrap 3 Alerts
<?php
/**
* Create a bootstrap success alert
* @param String $bold - First words in the alert. Will be put inside <strong> html tag for emphasis
* @param String $message - What will be used for the main description in the alert
*/
function successAlert($bold, $message){
echo '<div class="container">
<div class="alert alert-success fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>'.$bold.'</strong> '.$message.'
</div>
</div>';
}
/**
* Create a bootstrap danger alert
* @param String $bold - First words in the alert. Will be put inside <strong> html tag for emphasis
* @param String $message - What will be used for the main description in the alert
*/
function dangerAlert($bold, $message){
echo '<div class="container">
<div class="alert alert-danger fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>'.$bold.'</strong> '.$message.'
</div>
</div>';
}
/**
* Create a bootstrap info alert
* @param String $bold - First words in the alert. Will be put inside <strong> html tag for emphasis
* @param String $message - What will be used for the main description in the alert
*/
function infoAlert($bold, $message){
echo '<div class="container">
<div class="alert alert-info fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>'.$bold.'</strong> '.$message.'
</div>
</div>';
}
/**
* Create a bootstrap warning alert
* @param String $bold - First words in the alert. Will be put inside <strong> html tag for emphasis
* @param String $message - What will be used for the main description in the alert
*/
function warningAlert($bold, $message){
echo '<div class="container">
<div class="alert alert-warning fade in">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>'.$bold.'</strong> '.$message.'
</div>
</div>';
}
?>
<?php include 'Alert.php';?>
<html>
<head>
<title>Bootstrap Alert PHP</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Alerts</h2>
<!-- Just call the alert function you need and send in two strings - the alert header and the alert message -->
<?php
successAlert("Success!","This is a Bootstrap success alert");
infoAlert("Info!","This is a Bootstrap info alert");
warningAlert("Warning!","This is a Bootstrap warning alert");
dangerAlert("Danger!","This is a Bootstrap danger alert");
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment