开发者

submitting forms

I was wondering if some one disables javascript how will my form be submitted for checking with Php. One more thing I would like to know how can I perform something like this if the person clicks the submit button and PHP checks a 开发者_如何学Pythonfew fields if one of the fields is not valid I return an error in a div and if there is no error the script runs. I know how to perform the jquery ajax, mysql and stuff but submitting data if javascript is disabled is a bit confusing for me. I mean I wont be providing any form action so how will this all work. I hope I made some sense, Thanks.

// edited

Ok I got a few answers thanks it helped me understand how this all works. My final addition to the question is if I submit a form with no action it will be like submitting to itself. Will this cause the page to reload? and finally how can I cater the submit to do both things? Firstly validate through ajax and if everything is fine self submit and perform the php script even if javascript is disabled?


Welcome to HTML land, you might want to know about FORM and SUBMIT.

In this age of AJAX people forget that AJAX is just for making things nice and to consume less bandwidth. In the case of old-school brute-force approaches (like when Javascript isn't present) then we fall back on tried and true.


If you don't want to do an AJAX validation you can code PHP to validate the fields for you. POST the data and return a page with the same fields and messages explaining which fields did not validate.

It's also best to have PHP redundantly-validate the forms anyways to test for SQL-injection or if an outsider is posting random data to your pages. This is for security.

Can you also provide a code sample? Thanks.


I would add a hidden input to your form, whose default value is, say, 0. And, then, using JavaScript, I would change its value to, say, 1. Thus, when you send the form, if the input's value were still 0, the user doesn't have JavaScript enabled (or his browser simply doesn't suppor it), and, thus, his input has to be validated on the server side.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜