Show sourcecode
The following files exists in this folder. Click to view.
!kmom03_getform.php
aside.php
aside.php~
kmom02_changestyle.php
kmom02_changestyle.php~
kmom03_default.php
kmom03_default.php~
kmom03_encryptpassword.php
kmom03_encryptpassword.php~
kmom03_get.php
kmom03_get.php~
kmom03_getform.php
kmom03_getform.php~
kmom03_postform.php
kmom03_postform.php~
kmom03_server.php
kmom03_server.php~
kmom03_session.php
kmom03_session.php~
kmom03_sessionchange.php
kmom03_sessionchange.php~
kmom03_sessiondestroy.php
kmom03_sessiondestroy.php~
kmom03_setpagestyle.php~
kmom03_validate.php
kmom03_validate.php~
sql.php
kmom03_validate.php~
1 lines UTF-8 Unix (LF)
<h1>Form with validation</h1>
<form method="post"> <!-- action="?"> The action attribute is no longer needed in HTML5 --> <!-- Ändrade från "get" i getform.php till "post" -->
<fieldset>
<legend>Example of form whose entries get validated</legend>
<p>
<label for="input1">Användarkonto:</label><br>
<input id="input1" class="text" type="text" name="account">
</p>
<p>
<label for="input2">Lösenord:</label><br>
<input id="input2" class="text" type="password" name="password">
</p>
<p>
<input type="submit" name="doLogin" value="Login">
</p>
</fieldset>
</form>
<p>You called the page with the following query string:
<code><?php echo htmlentities($_SERVER['QUERY_STRING']); ?></code></p>
<p><code>$_GET</code> contains the following:</p>
<pre><?php print_r($_GET); ?></pre>
<p><code>$_POST</code> contains the following:</p>
<pre><?php print_r($_POST); ?></pre>
<?php
if(isset($_POST['account']))
{
echo "<p>The account variable is defined.";
if (empty(strip_tags($_POST['account']))) {
echo " However, it contains an empty string (aside from any tag that have been stripped away).";
}
echo "</p>";
if (!is_numeric($_POST['account']))
{
echo "<p>The account variable DOES NOT consist of only numerical characters.</p>";
}
else
{
echo "<p>The account varaible consists of ONLY numerical characters.</p>";
}
// Man kan fixa en sträng med NULL bytes, med ev. HTML- och PHP-taggar bortagna, så ingen sådan kod kan tas emot från postad form.
$text = $_POST['account'];
echo "<p>Using strip_tags, the account variable looks like: '" . strip_tags($text) . "'</p>";
}
else
{
echo "<p>The account variable is NOT defined.</p>";
}
?>