Notification Box in CSS - #1 HTML & PHP

Introduction:

This tutorial is on how to make a notification box for your website. This is the first of two parts, in which we will be creating the HTML and setting the messages.

Notification Box?

When I say a notification box, I mean one of those smooth and sliding information boxes which sometimes appear under certain circumstances on a website at the top of the page. Normally stating that the web page uses 'cookies'.

HTML:

First we want to create the HTML for our page. For the notification box HTML we are going to have a few elements... .outerBox - The entire width of the page to give a nice background colour .innerBox - Sets the location of the inner content .innerBox #information - The notification message. .innerBox #close - The box the user may click to close the notification box.
  1.         <head></head>
  2.         <body>
  3.                 <div class='outerBox'>
  4.                         <div class='innerBox'>
  5.                                 <p id='information'>Info.</p>
  6.                                 <p id='close'>X</p>
  7.                         </div>
  8.                 </div>
  9.         </body>
  10. </html>
The above HTML is now ready to appear as a notification box, however the message would always simply be 'Info.'. Normally this message would be something to do with server side queries such as the user trying to log in typed their information incorrectly, so we are going to output a PHP message there.

PHP:

First we set our PHP area...
  1. <?php
  2. ?>
Next we would execute our queries, and under the certain conditions we want to set a new information/notification message. We will create/set the value of a variable named 'message' for this...
  1. //Execute queries here, etc...
  2. $message = 'That username is not available!';
Now where we have our notification box HTML we want to first check if the $message variable is set in PHP, if it is, it means we have a message we want to output via a new notification box...
  1. if (isSet($message)) {
  2.         //Notification box code in here...
  3. }
Finally we want to change the 'Info.' from the notification box to the PHP message. Here is our final code...
  1. <?php
  2.         //Execute queries here, etc...
  3.         $message = 'That username is not available!';
  4. ?>
  5. <html>
  6.         <head></head>
  7.         <body>
  8.                 <?php
  9.                 if (isSet($message)) {
  10.                 //Notification box code in here...
  11.                 echo "
  12.                 <div class='outerBox'>
  13.                         <div class='innerBox'>
  14.                                 <p id='information'>".$message."</p>
  15.                                 <p id='close'>X</p>
  16.                         </div>
  17.                 </div>";
  18.                 }
  19.                 ?>
  20.         </body>
  21. </html>

Finished Part 1!

Add new comment