How can I check if user gave input to input-form and say if there is an error? I tried to put
if (!isset($_POST['email'])) {
die('You have to give an email address.');
}
but the problem here is that it appears also if the user goes to the page first time and has not gave any input. XHTML is the following:
<form action=<?php echo SITEADDRESS.'register.php'?> method="post">
<p>
<label for="email">Sähköposti:</label>
<input type="text" id="email" name="email" />
<label for="password">Salasana:</label>
<input type="password" id="pwd" name="pwd" />
</p>
<p>
<input type="submit" value="Rekisteröidy" />
</p>
</form>
You need to do so when user clicks the
submitbutton, so your code should look like this:Now the above code will only execute when a user clicks the submit button unlike when he visits the page without clicking the button. Hence, above code will execute only after a user click the submit button.
You should give the name to your submit button:
Note: Rather than using
die, you could show a message and continue to show your form something like this: