views:

39

answers:

3

I have several forms in one HTML page...

I have to filter these forms somewhere... (eg check if all or some form elements have values etc...)

I am using ajax to submit the forms, but i dont know if i should filter it before submitting it to my php file, or filtering it inside the php file?

I want the fastest way for the data to show up....

??????????????

Thanks

+2  A: 

Filter in both places. You cannot trust anything the client sends to your server, so always check in a server side script that what they sent is good. But you don't want your client to wait, so check using client side script as well.

Marius
Wont this make the website slow?
pesar
I agree with Marius. Client side checking enables you to filter content before a form submission even occurs, saving you some bandwidth and the user some precious time.
cballou
definately no. you can't sacrifice security for the sake of performance... not with the current powers.
ifesdjeen
Will what make the website slow?
Marius
In this case, the form is a classifieds form where users select different categories and subcategories, also price ranges if they wish... So what would be recommended in my case? Since there is no information that i want to keep hidden really!
pesar
A: 

Always consider that there are people out there, who have JavaScript deactivated. For them you need to check data at the server side.
Also the checks on JavaScript side could be manipulated (Firebug, etc) so you also have to check the data on the server side for people having JavaScript enabled.

Hippo
A: 

i would at first say that having multiple forms on one page is definitely not the best practice. especially if you're using Ajax to submit forms. use validation on the client-side along with server-side. consider using some framework, which can ease your life and give you some custom solutions.

ifesdjeen