Jump to content
w3schoon

Validates Form using PHP with Ajax & JQuery

Recommended Posts

Best practise involves pure Javascript on the client-side and PHP on the server-side. AJAX would just slow down the process. Validation, both on the client side and on the server side, is just comparing the form element's value to what you want it to be.

Share this post


Link to post
Share on other sites

I'm start confusing now for what you had said, I red that Ajax can do...

1. Live username checking2. Password confirmation and strength3. Checking if an email address is already registered4. URL validation, i.e. Basecamp's site address checks if the URL is available (pretty much the same as username validation) from: http://jqueryfordesi...validate-forms/
Can you tell me why
AJAX would just slow down the process. -Ingolme
? The reason why I became interested to use Ajax for validation of form is because of this http://jqueryfordesigners.com/demo/ajax-validation.php (do not click the link but copy & paste it in the URL bar) Edited by w3schoon

Share this post


Link to post
Share on other sites

Well, yes. I wouldn't call that validation. AJAX is the only way to check the existence of usernames, email addresses and URLs because they're outside of Javascript's capability. But I wouldn't send a request to the server just to check that a field was left empty or the the username has valid characters. Asking the server to do that with AJAX would be slower than just checking it with Javascript. If you're using AJAX to submit and process the form after the data has been validated then, yes, you don't need to worry about pure client-side validation.

Share this post


Link to post
Share on other sites

Thank you for the reply. After reading your replies, I came up with two questions: #1. What do you mean,

If you're using AJAX to submit and process the form after the data has been validated then, yes, you don't need to worry about pure client-side validation. -Ingolme
?Isn't it the PHP & not the Ajax that will do the job of submitting and processing the form after the data has been validated? #2. What do you mean,
Best practise involves pure Javascript on the client-side -Ingolme
?You mean I should only use pure Javascript for client-side validation & not with the JQuery or any other Javascript libraries? Sorry If I have too many questions, I just really want to learned from the experts :Pleased: Edited by w3schoon

Share this post


Link to post
Share on other sites

Hi w3schoon, I actually am in the process of finishing up a registration form that uses PHP with Ajax & JQuery. If you do your initial sanity checks in pure Javascript as Ingolme suggests then you can minimize the amount of requests to the server, then once you pass the initial javascript comparative checks you can pass your values with ajax so you can do things like checking if a username is available or not. I may even do some more pure javascript checks on my data just to minimize work on the server, however a registration page wont get worked nearly as much as other forms on the site. to your question:"Isn't it the PHP & not the Ajax that will do the job of submitting and processing the form after the data has been validated?" you can use php directly to submit and process the form, but this would cause you to leave your current page, so lets say you submit your data, the page would then have to go to another page or reload the current page, but with Ajax, you can verify if the username is already taken, without the need to reload the page.

Edited by xekon

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...