Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>PHP 1. Задание 3</title>
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
- </head>
- <body>
- <?php
- $elements = [
- [
- "element" => "input",
- "htmltype" => "text",
- "name" => "firstname",
- "type" => "string",
- "placeholder" => "Введите имя"
- ],
- [
- "element" => "input",
- "htmltype" => "text",
- "name" => "age",
- "type" => "integer",
- "placeholder" => "Введите возраст"
- ],
- [
- "element" => "input",
- "htmltype" => "radio",
- "name" => "gender",
- "type" => "boolean",
- "value" => "male",
- "label" => "мужской"
- ],
- [
- "element" => "input",
- "htmltype" => "radio",
- "name" => "gender",
- "value" => "female",
- "type" => "boolean",
- "label" => "женский"
- ],
- [
- "element" => "input",
- "htmltype" => "submit",
- "value" => "Отправить"
- ],
- ];
- //Создаем функцию, которая принимает массив с различными свойствами HTML-элемента , (включая его название
- //и атрибуты) и создает html-разметку этого тэга :
- function constructorForElement($OneHtmlElementInArray){
- foreach ($OneHtmlElementInArray as $key => $value) {
- if ($key == "element"){
- echo "<".$value." ";
- $endTag = "/>";
- }
- elseif($key == "htmltype"){
- echo " type=".$value." ";
- $endTag = "/>";
- }
- elseif($key == "label"){
- echo "/><label for=''>" . $value;
- $endTag = "</label>";
- }
- elseif($key == "type"){
- continue;
- }
- else {
- echo $key . "='".$value."' ";
- $endTag = "/>";
- };
- }
- echo $endTag;
- }
- //Создаем функцию htmlConstructor которая принимает многомерный массив HTML элементов и с помощью функции
- //constructorForElement создает разметку на основании многомерного массива
- function htmlConstructor($htmlElementsArray) {
- foreach($htmlElementsArray as $htmlElement) {
- echo "<div class = 'row'>";
- constructorForElement($htmlElement);
- echo "</div>";
- }
- }
- ?>
- <div class="container">
- <form action = "/" method = "post">
- <?php htmlConstructor($elements); ?>
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement