Advertisement
dimipan80

Sidebar Builder

Apr 23rd, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.72 KB | None | 0 0
  1. <!--Write a PHP program SidebarBuilder.php that takes data from several input fields and builds 3 sidebars.
  2. The input fields are categories, tags and months. The first sidebar should contain a list of the categories,
  3. the second sidebar – a list of the tags and the third should contain the months.
  4. The entries in the input strings will be separated by a comma and space ", ".
  5. Styling the page is optional. Semantic HTML is required.-->
  6.  
  7. <!DOCTYPE html>
  8. <html>
  9. <head lang="en">
  10.     <meta charset="UTF-8">
  11.     <title>Sidebar Builder</title>
  12.     <style type="text/css">
  13.         section {
  14.                 width: 60%;
  15.                 float: left;
  16.         }
  17.  
  18.         input[type="text"] {
  19.                     width: 300px;
  20.                 text-indent: 2px;
  21.         }
  22.  
  23.         aside {
  24.                 width: 35%;
  25.                 float: right;
  26.         }
  27.  
  28.         article {
  29.                 width: 80%;
  30.                 font-family: Tahoma, sans-serif;
  31.                 font-size: 18px;
  32.                 background-color: #FF0;
  33.                 padding: 5px 0 5px 15px;
  34.                 margin-bottom: 10px;
  35.                 border: 1px solid #000;
  36.                 border-radius: 20px;
  37.         }
  38.  
  39.         h2 {
  40.                 border-bottom: 1px solid #000;
  41.         }
  42.  
  43.         ul {
  44.                 list-style-type: circle;
  45.         }
  46.  
  47.         li {
  48.                 text-decoration: underline;
  49.         }
  50.     </style>
  51. </head>
  52. <body>
  53. <section>
  54.     <form method="post">
  55.         <p>
  56.             <label for="cats">Categories:</label>
  57.             <input type="text" name="cats" id="cats" autofocus required/>
  58.         </p>
  59.  
  60.         <p>
  61.             <label for="tags">Tags:</label>
  62.             <input type="text" name="tags" id="tags" required/>
  63.         </p>
  64.  
  65.         <p>
  66.             <label for="months">Months:</label>
  67.             <input type="text" name="months" id="months" required/>
  68.         </p>
  69.         <input type="submit" value="Generate"/>
  70.     </form>
  71.     <p>
  72.         <?php
  73.         if (!isset($_POST['cats']) || !isset($_POST['tags']) || !isset($_POST['months']) ||
  74.             trim($_POST['cats']) === '' || trim($_POST['tags']) === '' || trim($_POST['months']) === ''
  75.         ) {
  76.             die('Please, enter some text in Each Text-field on Input Form!!!');
  77.         }
  78.         ?>
  79.     </p>
  80. </section>
  81. <?php
  82. $categories = preg_split('/,\s+/', trim($_POST['cats']), -1, PREG_SPLIT_NO_EMPTY);
  83. $tags = preg_split('/,\s+/', trim($_POST['tags']), -1, PREG_SPLIT_NO_EMPTY);
  84. $months = preg_split('/,\s+/', trim($_POST['months']), -1, PREG_SPLIT_NO_EMPTY);
  85. ?>
  86. <aside>
  87.     <article>
  88.         <h2>Categories</h2>
  89.         <ul>
  90.             <?php
  91.             foreach ($categories as $categ):?>
  92.                 <li><?= htmlspecialchars($categ) ?></li>
  93.             <?php endforeach; ?>
  94.         </ul>
  95.     </article>
  96.     <article>
  97.         <h2>Tags</h2>
  98.         <ul>
  99.             <?php
  100.             foreach ($tags as $tag):?>
  101.                 <li><?= htmlspecialchars($tag) ?></li>
  102.             <?php endforeach; ?>
  103.         </ul>
  104.     </article>
  105.     <article>
  106.         <h2>Months</h2>
  107.         <ul>
  108.             <?php
  109.             foreach ($months as $month):?>
  110.                 <li><?= htmlspecialchars($month) ?></li>
  111.             <?php endforeach; ?>
  112.         </ul>
  113.     </article>
  114. </aside>
  115. </body>
  116. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement