I am trying to redirect to the same HTML page with an error message saying all fields are required if any of the fields are left empty. I am using Servlets, MYSQL, and HTML to build this project, I am able to store data in MYSQL but stuck at this point, Please help me.
You can use RequestDispatcher to dispatch your HTML resource. But you need to handle displaying error messages in client side (using JS). But it's better to use JSP, so you can achieve it easily
Well, since you didn't show any code, the whole idea is:
validate.js
var field = document.forms["form_name"]["user_input"].value;
if (field==null) {
alert("all fields are required");
return false;
}
validate.php
if(isset($_POST["user_input])){
$field = $_POST["user_input"];
if(empty($field){
echo "error, all fields are required"
}
Hope this helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.