chilli11 — 2010-11-12T12:20:09-05:00 — #1
I am re-developing my website and want to use some Ajax/jQuery in it (so I am learning as I go) and I am not sure if this is possible so that is my first question:
I have a registration form and I would like to know if after the person registering has completed their first and surname and the 2 sections of their postcode if I can use jQuery to run a PHP script to see if they are already registered before waiting for the form to be submitted and running a script then.
I am thinking onkeyup (or similar) after the last field is completed but I don't know how that would work needing to also use 3 other field values.
If this is possible, can anyone give me any ideas of examples that do this or how I can go about passing all the variables and running the scripts at the correct time.
Even if this is not possible I would like to know please so that I can stop looking for the answer.
chris_upjohn — 2010-11-12T19:53:25-05:00 — #2
chilli11 — 2010-11-15T04:01:17-05:00 — #3
Thank you - I have read this before and read it again over the weekend but I am still not sure how to implement the function(s) before the form is submitted.
Am I missing something?
paul_wilkins — 2010-11-15T04:14:25-05:00 — #4
The first step is checking that their first name, surname, and two postcode parts have information entered. Those are required fields.
Just set a class of required on those input fields, run the validate plugin and the rest is done for you.
After you have that working, you can then advance to the next level and use ajax to validate whether they are already registered.
chilli11 — 2010-11-15T04:20:52-05:00 — #5
Thank you - yes I can do the validate part (I haven't got a problem with that) it is how to pass that information through to an ajax function/script to then run the php to see if they are registered.
Do I create vars from the $_GET elements and pass them through to the url of the php script?
system — 2010-11-15T04:31:20-05:00 — #6
work through these w3schools ajax tutes and hopefully they will help.
paul_wilkins — 2010-11-15T04:34:00-05:00 — #7
Crating variables from $_GET is okay, but what happens after you've checked them is to then just output a value, such as "valid" or "invalid"
That value that you output from the php script is returned back to the web page as data. The ajax request fetches that data, so that your script can then take appropriate action based on that value.
With the validation script, if it's an invalid value you would then trigger the validation process for an invalid value.
They provide a demo of "remote validation" at http://jquery.bassistance.de/validate/demo/captcha/
which you can investigate to check out the details of how it's done.