Ich denke, Sie suchen nach etwas wie unten.
<?php
$x=rand('1000','9999');
echo $x;
?>
<script type="text/javascript">
var rand_value = "<?php echo $x?>";
</script>
<form method="post" onsubmit="return validateForm()" >
<input type="number" name="rnd" id="rnd">
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
function validateForm(){
x = document.getElementById("rnd").value;
if(rand_value == x){
alert("Match");
return true;
}else{
alert("Not-Match");
return false;
}
}
</script>
Wenn Sie auf Client-Seite tun Validierung möchten, sollten Sie JavaScript
verwenden.
sonst versuchen, diese
<?php
$x=rand('1000','9999');
echo $x;
?>
<form method="post">
<input type="hidden" name="myRnd" value="<?php echo $x; ?>">
<input type="number" name="rnd">
<input type="submit" value="Submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$x = $_POST['myRnd'];
$a = $_POST['rnd'];
if($a === $x){
echo "Match";
}
}
?>
??? Das sieht nach Hausaufgaben/Aufgaben aus ... aber stell wenigstens eine bessere Frage. – mroman