I am trying to make a form using HTML, PHP, and jQuery AJAX for a website but I don't know how to validate it. Where should I write the code to validate it, in PHP or jQuery?
1
-
1Firstly, this question is far too broad. Secondly, you need to write your validation logic in both JS and PHP. JS is to validate the form for user convenience, the PHP is to validate that the input meets business logic requirements.Rory McCrossan– Rory McCrossan2019-06-12 10:24:54 +00:00Commented Jun 12, 2019 at 10:24
Add a comment
|
1 Answer
I would suggest using javascript and html than any other language The following code is for browser validation
<input required> // info
<input required> // more info
<button type="submit">Press to validate</button>
</form>
When you click the button the form will be validated
For js validation
<button onclick ="myfunction()">Press to validate</button>
<script>
function myfunction(){
var x =document.getElementById('validate');
if (x.value.length < 1){
alert("Empty input box.Form validated")
}
}
</script>
Hope this helps
3 Comments
sidrao2006
What is the problem in the answer
Jay Blanchard
Jay Blanchard
You should ALWAYS validate on the server-side. Client-side code is easily hacked and bypassed and should only be used as a convenience.