Hiding the Form After Submission in PHP
Let's say we have a form where two numbers are entered. Let's also assume that after submitting the form, we display the sum of these numbers:
<form action="" method="GET">
<input name="test1">
<input name="test2">
<input type="submit">
</form>
<?php
if (!empty($_GET)) {
echo $_GET['test1'] + $_GET['test2'];
}
?>
Let's make it so that the form is hidden after submission. To do this, the form code needs to be placed inside a condition:
<?php
if (empty($_GET)) {
?>
<form action="" method="GET">
<input name="test1">
<input name="test2">
<input type="submit">
</form>
<?php
} else {
echo $_GET['test1'] + $_GET['test2'];
}
?>
Using a form, ask for the user's name. After submitting the form, greet the user by name and remove the form.