1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
PHP_TP1/helloworld3.php

45 lines
1.1 KiB
PHP
Raw Normal View History

2020-10-01 08:41:35 +02:00
<?php
$nb = null;
$name = null;
$error = false;
if (isset($_GET["nb"]) AND isset($_GET["name"])) {
$nb = (int)$_GET["nb"];
$name = htmlspecialchars($_GET["name"]);
if ($nb < 0 or $nb > 100) {
$error = true;
$nb = null;
$name = null;
}
}
?>
2020-09-10 15:56:55 +02:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello World 3</title>
</head>
<body>
<form>
<label for="nb">Number: </label>
<input id="nb" type="number" name="nb" min="0" max="100" value="<?= $nb ?>" required>
<label for="name">Name: </label>
<input id="name" name="name" value="<?= $name ?>" required>
<input type="submit" value="Send">
</form>
2020-10-01 08:41:35 +02:00
<?php
if ($error) { ?>
<strong>Invalid args !</strong>
<?php } ?>
2020-09-10 15:56:55 +02:00
<ul>
2020-10-01 08:41:35 +02:00
<?php if ($nb !== null AND $name !== null) {
for ($i = 0; $i < $nb; $i++) { ?>
<li>Hello <?= $name ?> !</li>
2020-09-10 15:56:55 +02:00
<?php }
2020-10-01 08:41:35 +02:00
}?>
2020-09-10 15:56:55 +02:00
</ul>
</body>
2020-10-01 08:41:35 +02:00
</html>