francoleung
francoleung

Reputation: 257

How prevent user to change form input value from browser debug tools?

I would like to create a HTML form ,the user can input his name and submit, but the user does not fill in the name input, the system will not submit and show the error message in alert box.

Here is my code about form.php

<form name="myForm" action="b.php" method="post">
Name: <input type="text" name="fname">
<input type="submit" value="Submit" onclick="return validateForm()">
</form>

<script>
function validateForm() {
    var x = document.forms["myForm"]["fname"].value;
    if (x == "") {
        alert("Name must be filled out");
        return false;
    }
}
</script>

and submit successful,the information will go to this page b.php b.php

    <?php
echo $_POST[fname];
?>

But When the user use browser debug tools(like chrome),They can change form input "name" "id" "class" .etc value, In this case, when the user change the form name value, the form can submit without fill in the name.

any idea to solve this problem.....or use javascript to Validation is not a good choice????? Thanksenter image description here

enter image description here

enter image description here

enter image description here

Upvotes: 2

Views: 3157

Answers (1)

Muhammad Habib
Muhammad Habib

Reputation: 119

Server side validation will handle this. Return the page back to the form if the input values is empty or anything.

Upvotes: 3

Related Questions