Я делаю форму, но я не работаю так, как хочу.Это код:
<?php
$output = '';
$display_form = True;
//echo $display_form;
//Once the form is submitted it should be hidden so first I set $display_form to false at line 19.
//Then I do all the logic to get the propper result at line 21-39. And echo the result at line 40-43.
if(isset($_POST['submit'])){
$display_form = False;
if (!is_numeric($_POST['mark1'])) {
$mark1 = $_POST['mark1'];
$output = 'De invoer van Getal 1 was foutief: '.$mark1;
}if(!is_numeric($_POST['mark2'])) {
$mark2 = $_POST['mark2'];
$output.= '<br>De invoer van Getal 2 was foutief '.$mark2;
}elseif(is_numeric($_POST['mark1']) && is_numeric($_POST['mark2'])){
$mark1 = str_replace(',', '.', $_POST['mark1']);
$mark2 = str_replace(',', '.', $_POST['mark2']);
$result = $mark1+$mark2;
$mark1_2 = str_replace('.', ',', $mark1);
$mark2_2 = str_replace('.', ',', $mark2);
$result_2 = str_replace('.', ',', $result);
$output = $mark1_2.' + '.$mark2_2. ' = '.$result_2.'<br>';
}?>
<h1>
<?php echo $output ?>
</h1>
<button type="reset" value="Opnieuw">Opnieuw</button>
<?php
}
//If the form isn't submitted $display_form is True so it should show this HTML
if($display_form){ ?>
<h1>Optel rekenmachine</h1>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
Getal 1: <input type="text" name="mark1"><br>
Getal 2: <input type="text" name="mark2"><br>
<button type="submit" value="Optellen!"class="form">Optellen!</button><button type="reset" value="Leegmaken">Leegmaken</button>
</form>
<?php }
?>
Я хочу, чтобы он показывал форму, но как только она будет отправлена, я хочу, чтобы форма скрывала результаты поиска.Когда результаты отображаются, появляется кнопка «Opnieuw».После того, как вы нажмете, форма должна снова появиться и результаты с кнопкой opnieuw должны скрыться.Но сейчас форма не дает результатов и не скрывает, а просто сбрасывает ее после отправки.