Help complete please.
This code is used to decode a json file from a directory and create a test from it. I need that when sending the form, the entered values are recorded in an array and at the end the result is how many correct answers, how many are not correct. I, probably, did not set the correct format for the form, can it be easier to implement using selection markers, and send the results with one button?
<?php $test_dir = "./tests/test"; $test_id = $test_dir.$_GET["id"].".json"; $json_file = file_get_contents($test_id); $json_array = json_decode($json_file, true); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="style.css"> </head> <body> <nav> <ul> <li><a href="list.php">Список тестов</a></li> <li><a href="admin.php">Загрузить тест</a></li> </ul> </nav> <?php echo "<pre>"; var_dump($json_array); $result=[]; ?> <form action="" method="GET" enctype="multipart/form-data"> <h1><?php echo $json_array[0]['question'] ?></h1> <h2>Варианты ответов:</h2> <?php foreach ($json_array[0]['answers'] as $values) { ?> <p> <?php echo $values; ?> </p> <?php } ?> Напишите номер ответа: <input type="text" name="question1" value=" "><br> <input type="submit" value="Ответить"> </form> <form action="" method="GET" enctype="multipart/form-data"> <h1><?php echo $json_array[1]['question'] ?></h1> <h2>Варианты ответов:</h2> <?php foreach ($json_array[1]['answers'] as $values) { ?> <p> <?php echo $values; ?> </p> <?php } ?> Напишите номер ответа: <input type="text" name="question2" value=" "><br> <input type="submit" value="Ответить"> </form> <form action="" method="GET" enctype="multipart/form-data"> <h1><?php echo $json_array[2]['question'] ?></h1> <h2>Варианты ответов:</h2> <?php foreach ($json_array[2]['answers'] as $values) { ?> <p> <?php echo $values; ?> </p> <?php } ?> Напишите номер ответа: <input type="text" name="question3" value=" "><br> <input type="submit" value="Ответить"> </form> <?php $answer1 = $_GET['question1']; $answer2 = $_GET['question2']; $answer3 = $_GET['question3']; $result = [$answer1, $answer2, $answer3]; echo "<pre>"; var_dump($result); ?> </body> </html> Below is the structure of the json test.
[{ "question": "Столица России?", "answers": { "1": "1. Париж", "2": "2. Вашингтон", "3": "3. Питер", "4": "4. Москва" }, "correct_answer": "4" }, { "question": "Какой сейчас год?", "answers": { "1": "1. 2025", "2": "2. 1991", "3": "3. 2017", "4": "4. 2013" }, "correct_answer": "3" }, { "question": "Сколько дней в январе?", "answers": { "1": "1. 31", "2": "2. 29", "3": "3. 30", "4": "4. 28" }, "correct_answer": "1" }]