473,320 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

PHP/AJAX Form Validation - How to?

Haitashi
I have a multi-page form. The first page asks for an email and password. I want the user to enter their email address & password twice before they can click submit. The post action on this page is the second page of this form.

I wanted to include a script that would check if both emails and both passwords match on the fly; this is so they can receive a "live" response telling them that the emails don't match before they move on to the password or a warning telling then that the passwords don't match before the "submit" button becomes visible.

Thanks!! ^_^
Jul 16 '07 #1
3 1468
gits
5,390 Expert Mod 4TB
hi ...

you may call a validation function onsubmit of your form. when that function returns false the submit is stopped and you may give the hint why ;) ... you only have to compare the values of your inputboxes ... but be aware: you should check that on the server too ... because the script may be modified by the users locally ... so you cannot rely on it in case it is security-relevant ...

try something and post it here in case you have particular problems ...

kind regards

ps: hints are onsubmit of your form, a function that returns true or false, values of your textboxes
Jul 16 '07 #2
Ok, I see.

I have something like this so far:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function validate_email(field,alerttxt)
  5. {
  6. with (field)
  7. {
  8. apos=value.indexOf("@")
  9. dotpos=value.lastIndexOf(".")
  10. if (apos<1||dotpos-apos<2) 
  11.   {alert(alerttxt);return false}
  12. else {return true}
  13. }
  14. }
  15.  
  16. function validate_form(thisform)
  17. {
  18. with (thisform)
  19. {
  20. if (validate_email(email,"Not a valid e-mail address!")==false)
  21.   {email.focus();return false}
  22. }
  23. }
  24. </script>
  25. </head>
  26.  
  27. <body>
  28. <form action="submitpage.htm"
  29. onsubmit="return validate_form(this);"
  30. method="post">
  31. Email: <input type="text" name="email" size="30">
  32. <input type="submit" value="Submit"> 
  33. </form>
  34. </body>
  35.  
  36. </html>
How can I change the warning so that instead of a warning box, the user just gets some text next to the field with the warning information?
Jul 16 '07 #3
gits
5,390 Expert Mod 4TB
create a div in the position you need and set its innerHTML with the text you want to display ...

you're doing well ;)

kind regards
Jul 16 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

31
by: Tony | last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET distribution - I'm pretty concerned about this. Does anyone know if this is the same "prototype.js" that is not well-liked...
1
by: AECL_DEV | last post by:
Hello Everyone, Ive seen alot of people saying that the best way to AJAX Validate a form is through the submit button, because validation should be synchronous. Im wondering, is there any good...
5
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only...
1
by: John Chan | last post by:
Hi, Im doing a maintenance application in ajax and coldfusion at work on IE6 exclusively. I have a save button on each form and i have to do various validations server side and on client side...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
3
rizwan6feb
by: rizwan6feb | last post by:
Hi experts! Recently i was working on "Form Validation Using Ajax". My form validation was creating problem, when a user changes focus too quickly. I had a post related to this, but was unable to...
1
by: Mark B | last post by:
This is my first try at using AJAX. I want the calendars to be enabled if the user checks CheckBox1. It works OK for a normal all page refresh but once I introduced the AJAX code it stopped...
3
pradeepjain
by: pradeepjain | last post by:
hii guys , I wanna share a very gud ajax validation script with php... Ajax Form Validation - sForm | chains.ch weblog I am very new to ajax .So i wanna small help....i want to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.