Saving Form Default Value in PHP
Suppose we want to have some text already in the input when the page is first accessed. The user can edit this text or leave it unchanged. And after form submission, the input should contain the text that was present at the time of submission.
To solve this problem, we need to add
a else block to our condition and in this
block output the default value:
<form action="" method="GET">
<input
name="test"
value="<?php
if (isset($_GET['test']))
echo $_GET['test'];
else echo 'default'
?>"
>
<input type="submit">
</form>
Using a form, ask the user for a year. After submission, determine whether this year is leap or not. Make sure that on the first visit to the page, the current year is already set in the input.