Last active
December 19, 2015 14:48
-
-
Save ccagle8/5971898 to your computer and use it in GitHub Desktop.
A simple way to display Twitter Bootstrap messages dynamically with PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Display Alert Messages | |
* | |
* Looks for a global variable, and displays any test that variable has | |
* | |
* @uses GLOBALS $notice, $error, $success, $infonotice, $alertBlock | |
* @return string | |
*/ | |
function display_messages() { | |
global $success; | |
global $error; | |
global $notice; | |
global $infonotice; | |
global $alertBlock; | |
if ($alertBlock) $alertBlock = ' alert-block '; | |
if ($notice) { | |
echo '<div class="alert '.$alertBlock.'"><button type="button" class="close" data-dismiss="alert">×</button>'. $notice .'</div>'; | |
} | |
if ($error) { | |
echo '<div class="alert alert-error '.$alertBlock.'"><button type="button" class="close" data-dismiss="alert">×</button>'. $error .'</div>'; | |
} | |
if ($success) { | |
echo '<div class="alert alert-success '.$alertBlock.'"><button type="button" class="close" data-dismiss="alert">×</button>'. $success .'</div>'; | |
} | |
if ($infonotice) { | |
echo '<div class="alert alert-info '.$alertBlock.'"><button type="button" class="close" data-dismiss="alert">×</button>'. $infonotice .'</div>'; | |
} | |
} | |
# test the messages | |
$error = 'Your payment has failed.'; | |
$success = 'Your payment has succeeded!'; | |
$notice = '<b>Tip:</b> When walking, you should have your eyes opened.'; | |
$alertBlock = true; | |
$infonotice = '<h4>Welcome!</h4><p>Thanks for signing up. Check out this <a href="">great tutorial</a> to get you started.</p>'; | |
?> | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<title>Twitter Bootstrap Messages</title> | |
<!-- Dont forget to download and use your own copy --> | |
<link href="http://twitter.github.io/bootstrap/assets/css/bootstrap.css" rel="stylesheet"> | |
</head> | |
<body> | |
<?php display_messages(); ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment