Calculator check for all values in submit

This commit is contained in:
Kilian Hofmann 2024-05-03 13:32:21 +02:00
parent a8fc2f3c13
commit 14c79c52e6

View File

@ -22,7 +22,7 @@
$result = "";
if (
array_key_exists("operand1", $_POST) &&
isset($_POST["operand1"], $_POST["operand2"], $_POST["operator"]) &&
is_numeric($_POST["operand1"]) &&
is_numeric($_POST["operand2"])
) {
@ -55,7 +55,7 @@
<form method="post" class="p-3 needs-validation" novalidate>
<div class="mb-3">
<label class="form-label" for="operand1">Operand 1</label>
<input class="form-control" id="operand1" type="number" name="operand1" value="0" required step="any" />
<input class="form-control" id="operand1" type="number" name="operand1" value="<?php echo is_numeric($result) ? $result : 0 ?>" required step="any" />
<div class="invalid-feedback">
Please enter a number
</div>
@ -66,7 +66,6 @@
<div class="invalid-feedback">
Please enter a number
</div>
</div>
<label class="form-label">Operator</label>