How can i validate that the user type in time in my form? I whill that the user use the format 16:30 (24h) If wrong the page jump back or the message "wrong time" appears and link back to the page like java history? i have try the split command.
This is my code:
<?php
if (isset($_POST['Submit'])) {
echo "submitted <br>";
echo $txt_time_from."<br>";
$str = $txt_time_from;
$pat = " ";
$arr = split($pat, $str);
echo ("$arr[0] - $arr[1]")."<br>";
if ($arr[0] < 0 || $arr[0] > 24 ) {
echo "vad e det för en tid";
echo "<FORM><INPUT type=\"button\" value=\"Click here to go back\" onClick=\" history.back()\"></FORM>";
exit;
}
// if (!($arr[1] == 0 || $arr[1] == 15 || $arr[1] == 30 || $arr[1] == 45)) {
/ die ('minutes wrong chose 00, 15, 30 or 45 <br>
<FORM><INPUT type="button" value="Click here to go back" onClick=" history.back()"></FORM>');
}
/} else {
echo"bluff";
}
function Backa() {
echo "<FORM><INPUT type=\"button\" value=\"Click here to go back\" onClick=\" history.back()\"></FORM>";
end;
}
?>
<form action="" method="post" name="data_frm" id="data_frm">
<p>Today date:
<input name="txt_reg_date" type="text" value="<?php echo time() ?>" disabled>
<!-- <input type="hidden" name="hiddenField"> -->
Reg. by:
<input name="textfield2" type="text" value=" <?php echo $User_Name?>" disabled>
</p>
<p>Date:
<input name="txt_date" type="text" value=" <?php echo "$c_date / $c_month - $c_year"?>" disabled>
From time
<input name="txt_time_from" type="text" size="8" maxlength="5">
To time
<input name="txt_time_to" type="text" size="8" maxlength="5">
</p>
<p>Notes
<input name="notes" type="text" size="60" maxlength="100">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
<?php $datetime_array = getdate(); //populate associative array
?>