我有以下表单验证。
String[] strArr = {"p1", "p2", "p3"};
System.out.printf("%1$s %2$10s %2$10s", strArr );
验证工作正常,如果没有错误,它应该发出警报。但是,当我提交没有错误的表单时,我没有看到警告消息。我该如何解决这个问题?
答案 0 :(得分:1)
试试这个
<?php
$error_occured = 0;
$error_name = "";
$error_email = "";
$error_contact = "";
$error_comments = "";
if(isset($_POST["tx_name"])) {
if(($tx_name == "") || (!preg_match("/^[a-zA-Z ]*$/",$tx_name))) {
$error_occured = 1;
$error_name = "Please enter a valid name";
}
if(($tx_email == "") || (!filter_var($tx_email, FILTER_VALIDATE_EMAIL))) {
$error_occured = 1;
$error_email = "Please enter a valid email";
}
if(($tx_contact == "") || !(is_numeric($tx_contact))) {
$error_occured = 1;
$error_contact = "Please enter a valid contact number";
}
if($tx_comments == "") {
$error_occured = 1;
$error_comments = "Please enter your message";
}
if($error_occured != 1) {
echo "<script>alert('Hi!');</script>";
}
}
?>