Jump to content
mahenda

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

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

Share this post


Link to post
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

Share this post


Link to post
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?!

Share this post


Link to post
Share on other sites

Don't print both?

Seriously, you've given me a tiny bit of code way out of context. I can't do much with that.

If you want to do some basic validation with just Javascript then that's fine, but if it fails validation you don't then submit that to the server.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
1 hour ago, NotSunfighter said:

Why use JS?

Because you cannot customize the "required" validation warning that the browser gives the user. Or "pattern", which is going to tell the user something cryptic they won't possibly understand.

Share this post


Link to post
Share on other sites

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.