The essence of the task is as follows: it is necessary to develop a script that will check whether the required form fields are filled. If the fields are not filled, then we display a hint for what you need to fill out. In another case, we display information about the user. All of the ideas should be in the same file with the extension php. There are three functions in the code: print_form displays the form on the screen; check_form checks whether the required fields are filled in; confirm_form displays the output data
<html> <head> <title>Контактна інформація </title> </head> <body> <?php $f_name=$_POST['f_name']; $l_name=$_POST['l_name']; $email=$_POST['email']; $zip=$_POST['zip']; $object=$_POST['object']; function print_form($f_name,$l_name,$email,$zip,$object) { ?> <form action="form_start.php" method="post"> <table cellspasing="2" cellpedding="2" border="1"> <td>Ім'я</td><td><input name="f_name" type="text" value="<?php echo $f_name ?>"></td> </tr> <tr> <td>Прізвище<b>*</b></td><td><input name="l_name" type="text" value="<?php print $_name?>"</td> </tr> <tr> <td>Email адреса<b>*</b></td><td><input name="email" type="text" value="<?php print $email?>"> </td> </tr> <tr> <td>Поштовий індекс<b>*</b></td> <td><input name="zip" type="text" value="<?php print $zip?>"> </td> </tr> <tr> <td>Улюблений предмет</td> <td><input name="object" type="text" value="<?php print $object?>"> </td> </tr> </table> <input name="submit" type="submit" value="Надіслати"> <input type="reset" value="Відмінити"> </form> <? } function check_form($f_name,$l_name,$email,$zip,$object) { if(!$l_name||!$email||!$zip):echo "<h3>Помилка у заповнені форми</h3>"; if($l_name) { echo"<h3>Ви не заповнили поле<b>Прізвище</b></h3>"; } if(isset($email)) { echo "<h3>Ви не заповнили поле <b>Email адреса</b></h3>"; } if(!$zip) { echo "<h3>Ви не заповнили поле <b>Поштовий індекс</b></h3>"; } print_form($f_name,$l_name,$email,$zip,$object); else: confirm_form($f_name,$l_name,$email,$zip,$object); endif; } function confirm_form($f_name,$l_name,$email,$zip,$object) { ?> <h2>Дякуємо! Слідуюча інформація була успішно надіслана</h2> <b>Контактна інформація</b> <? $f_name=$_POST['f_name']; $l_name=$_POST['l_name']; $email=$_POST['email']; $zip=$_POST['zip']; $object=$_POST['object']; echo "<br>$f_name $l_name<br>$email<br>Поштовий індекс:$zip<br>Улюблений предмет:$object\n"; } if(!$submit): ?> <h3>Будь-ласка, введіть інформацію про себе</h3> Поля з<b>*</b>обовязкові для заповнення<p> <?php print_form("","","","","",""); else: check_form($f_name,$l_name,$email,$zip,$object); endif; ?> </body> </html>