Jump to content

Let's discuss about registration form. What's the best way to validate form?!


mahenda

Recommended Posts

Is jquery/Ajax better than real/raw PHP for form validation ?!

What if JavaScript is turned off on the browser?!

why after someone refreshing a page on the browser, the variables used to echo error after invalid data is being submitted will return the undefined variables error?!

And how to handle form validation including an empty form field, maximum amount of value entered and so on

Link to comment
Share on other sites

41 minutes ago, mahenda said:

Is jquery/Ajax better than real/raw PHP for form validation ?!

No. Validating on the user's computer means telling it what to do and hoping that it happens. You must validate on the server, and you may validate on the client too.

41 minutes ago, mahenda said:

What if JavaScript is turned off on the browser?!

That sounds like a good reason to not only do validation on the client.

41 minutes ago, mahenda said:

why after someone refreshing a page on the browser, the variables used to echo error after invalid data is being submitted will return the undefined variables error?!

Because your code and/or design is flawed.

41 minutes ago, mahenda said:

And how to handle form validation including an empty form field, maximum amount of value entered and so on

Handle it in whatever way you want as long as it works the way you need it to work.

  • Like 1
Link to comment
Share on other sites

Check here

If(empty($username){

echo ' user name is required';

}

At the same time

We have written a jQuery that prompt the message  'user name is required' if he/she submit an empty value.

Here all warning message will be printed at the same time, and it is going to be a bad idea since we have two messages at the same time.

So how to handle this?!

Link to comment
Share on other sites

Also, be aware that client-side code can be tampered with. JavaScript validation can be deleted / modified without disabling JavaScript. The "required" attribute can be removed. Hidden values can be modified. Extra input tags can be added.

Client-side validation should be seen more as a convenience to the user. You can let them know when something is wrong before the form is submitted. However, you should not trust that validation. Sever-side validation should be implemented to prevent tampering.

Edited by cyberRobot
fixed typo
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.