Citat:
Ursprungligen postat av
keepcalm8
Det dyker inte upp nåt "You didn't enter anything" när man inte skriver nåt i boxen.
[PHP]<?php
if (isset($_GET['username'])) {
echo "Welcome, " . $_GET['username'];
}
elseif (isset($_GET['submit']) && empty($_GET['username'])) {
echo "You didn't enter anything.";
}
else { echo "Default"; } ?>
<form id="formly" action="test.php" method="GET">
<input type="text" name="username">
<input type="submit" value="Click Me!">
</form>[/PHP]
Du har inte något som heter ”submit ” lägg på name=”submit” och sanitize input för att undvika xss attacker
Ex:
[PHP]
<?php
if (isset($_GET['submit']) && empty($_GET['username'])) {
echo "You didn't enter anything.";
}
if (isset($_GET['submit']) && !empty($_GET['username'])) {
// sanitize input to prevent XSS attacks
$username = htmlspecialchars($_GET['username']);
echo "Welcome, " . $username;
}
if (!isset($_GET['submit'])) {
echo "Default";
}
?>
<form id="formly" action="test.php" method="GET">
<input type="text" name="username">
<input type="submit" name="submit" value="Click Me!">
</form>
[/PHP]