www.webdeveloper.com
Results 1 to 7 of 7

Thread: PHP Class and Ajax in action!!

  1. #1
    Join Date
    Mar 2014
    Posts
    70

    PHP Class and Ajax in action!!

    I am a php class that is validating input fields.. I want to use ajax ..

    Details:

    ValidationClass.php
    Regis.php // registration page

    as my form action is self... so i am validating on the same page!!!

    Should i create a separate page for AJAX response! as ajax check the echo's from any specific page!!

    More if i want to get the response for two fields should i write the ajax two times?

    Any hint or a standard way? Plz

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,322
    I would submit all the fields as once (e.g., submit the whole form) to the validation PHP script, and have the script return a JSON object with all the validation results, which the JavaScript response handler could then loop through.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2014
    Posts
    70
    but if i want to append the error messages at the front of each field how can i do.. more check the availability of any specific field like email?

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,322
    At that point, it really becomes a JavaScript question. If you're using JQuery, it should be relatively easy to loop through the JSON object and apply it to the form elements -- just make sure that (a) you have useful id elements in each HTML form element so that your JQuery can easily reference them, and that your PHP returns those ID's in its response elements (e.g. it's easiest to make the ID and the form name the same:
    HTML Code:
    <label for="last_name">Last Name:<span id="last_name_error"></span></label>
    <input type="text" name="last_name" id="last_name" /></div>
    With that, if you get an error message for "last_name", you could just reference "last_name_error" as the element to add your error text to (or clear its value if that field no longer has an error but some other field does).

    And I suspect the real JavaScript experts here (I'm a hack, at best) could give you better ideas.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Mar 2014
    Posts
    70
    what do u mean by this

    //If you're using JQuery, it should be relatively easy to loop through the JSON object

    how to use to generate errors at the front of each field on keyup ?

  6. #6
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    html5 has built-in validation for form fields and there are polyfills for non-compliant browsers.
    that should be enough to "generate errors at the front of each field on keyup".
    in a situation where a user signs up or logs in, i would rely on php to validate authentication.
    10 times out of 10 you can bypass javascript, not to mention you can submit the form to the server without a web browser or even from the page the form is on.

  7. #7
    Join Date
    Mar 2014
    Posts
    70
    on sign up i just want to check the availability of my two fields

    1-email:
    1-DepID:

    check from database and then show messages at the front of input fields?

    i am using ajax for this.. i dot want to write ajax call two times for validation from database..

    got?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles