SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Shropshire
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Run JQuery/PHP script after 4 form fields entered and form not submitted

    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.

    Thanks

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  3. #3
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Shropshire
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    Shropshire
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    Non-Member Kalon's Avatar
    Join Date
    Aug 2010
    Location
    At my computer
    Posts
    2,012
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by chilli11 View Post
    ........it is how to pass that information through to an ajax function/script to then run the php to see if they are registered.
    work through these w3schools ajax tutes and hopefully they will help.

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by chilli11 View Post
    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?
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •