开发者

form validation in php and javascript

We often see in a standard input form that , if the values do not match the input criteria , then ,come whatever may , even after clicking on the submit button the data is开发者_如何转开发 not inserted into database.The question is, how do you prevent erroneous data from entering into the table.


Data can be validated "server-side" or "client-side". If what you want is to validate it BEFORE sending it to the server, then what you need is a "client-side" validation. In order to do that, you need to use Javascript (see: Form validation with Javascript).

Even if you validate your data with Javascript, this won't prevent inserting erroneous data into your Database (for example, javascript may not be enabled in the client). For this, you need "server-side" validation using php.

For better results, use both. Javascript will prevent sending erroneous data every time (less load for your server) and PHP will help you to keep your data reliable.


have some javascript or python filter so an onSubmit() function occurs before actual submission

e.g.

<input type="submit" onsubmit="submitFunc()" />

where submitFunc() is defined earlier on

<script type="text/javascript">

function submitFunc(username, password) {

if (!username) {

document.write("Uh oh! username not valid!")

}

if (!password) {

document.write("Uh oh! password not valid!")

}

}

</script>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜