Advertisement
dzimmo

Untitled

May 19th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.82 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7.     <title>PHP 1. Задание 3</title>
  8.     <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
  9. </head>
  10. <body>
  11.    
  12.     <?php
  13.     $elements = [
  14.  [
  15.    "element" => "input",
  16.    "htmltype" => "text",
  17.    "name" => "firstname",
  18.    "type" => "string",
  19.    "placeholder" => "Введите имя"
  20.  ],
  21.  [
  22.    "element" => "input",
  23.    "htmltype" => "text",
  24.    "name" => "age",
  25.    "type" => "integer",
  26.    "placeholder" => "Введите возраст"
  27.  ],
  28.  [
  29.    "element" => "input",
  30.    "htmltype" => "radio",
  31.    "name" => "gender",
  32.    "type" => "boolean",
  33.    "value" => "male",
  34.    "label" => "мужской"
  35.  ],
  36.  [
  37.    "element" => "input",
  38.    "htmltype" => "radio",
  39.    "name" => "gender",
  40.    "value" => "female",
  41.    "type" => "boolean",
  42.    "label" => "женский"
  43.  ],
  44.  [
  45.    "element" => "input",
  46.    "htmltype" => "submit",
  47.    "value" => "Отправить"
  48.  ],
  49. ];
  50.  
  51. //Создаем функцию, которая принимает массив с различными свойствами HTML-элемента , (включая его название
  52. //и атрибуты) и создает html-разметку этого тэга :
  53. function constructorForElement($OneHtmlElementInArray){
  54. foreach ($OneHtmlElementInArray as $key => $value) {
  55.         if ($key == "element"){
  56.             echo "<".$value." ";
  57.             $endTag = "/>";
  58.         }
  59.         elseif($key == "htmltype"){
  60.             echo " type=".$value." ";
  61.             $endTag = "/>";
  62.         }
  63.         elseif($key == "label"){
  64.             echo "/><label for=''>" . $value;
  65.             $endTag = "</label>";
  66.         }
  67.         elseif($key == "type"){
  68.             continue;
  69.         }
  70.         else {
  71.             echo $key . "='".$value."' ";
  72.             $endTag = "/>";
  73.         };
  74. }
  75. echo $endTag;
  76. }
  77. //Создаем функцию htmlConstructor которая принимает многомерный массив HTML элементов и с помощью функции
  78. //constructorForElement создает разметку на основании многомерного массива
  79. function htmlConstructor($htmlElementsArray) {
  80.     foreach($htmlElementsArray as $htmlElement) {
  81.     echo "<div class = 'row'>";
  82. constructorForElement($htmlElement);
  83.     echo "</div>";
  84.     }
  85. }
  86.     ?>
  87.     <div class="container">
  88.         <form action = "/" method = "post">
  89.             <?php htmlConstructor($elements); ?>
  90.         </form>
  91.     </div>
  92. </body>
  93. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement