How do you validate a form without refreshing the page?

Discussion in 'PHP' started by Imozeb, Feb 17, 2010.

  1. #1
    I'm planning to make a chat function using AJAX, javascript, and HTML and I figured I would use AJAX to send the form (text) to the server and store it in a text file that can be sent to other people using my chat function through AJAX so the page doesn't have to refresh. But now I'm starting to get worried about security because even though I know how to validate my form through javascript, people can disable it.

    Is there any way I can get PHP to validate my form before it is sent through AJAX to the server without refreshing the page?

    And yes, I know I could just download someone elses chat function, but wheres the fun in that? lol :D

    ~imozeb :D
     
    Imozeb, Feb 17, 2010 IP
  2. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use simple php validation techniques
    similar to javascript but the response will be through php
     
    xenon2010, Feb 17, 2010 IP
  3. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    But won't sending it through PHP refresh the page?
     
    Last edited: Feb 17, 2010
    Imozeb, Feb 17, 2010 IP
  4. Dondon2d

    Dondon2d Peon

    Messages:
    3,193
    Likes Received:
    146
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You were talking about AJAX, you can use that to validate real-time :)
     
    Dondon2d, Feb 17, 2010 IP
  5. SEOHow

    SEOHow Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Send the POST request using AJAX to a php validation script. Now that script can send the result of validation back to the browser.
     
    SEOHow, Feb 17, 2010 IP
  6. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Okay, is this right?

    Submit part: (User submits form, sends to javascript file for validation, sends to PHP file for validation, saves in .txt file)
    Output part: (Uses AJAX to get .txt info and outputs to page using <div> tags)


    And if I'm understanding correct, if a different PHP file (not the current page) submits the form the current page doesn't have to be refreshed?
     
    Last edited: Feb 17, 2010
    Imozeb, Feb 17, 2010 IP
  7. ryantetek

    ryantetek Peon

    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    this is how will it go(to avoid page refresh):

    Submit part: (User submits form, sends to javascript file for validation, use AJAX to transport data to PHP file,PHP file validates, saves in .txt file)
    Output part: (Uses AJAX to get .txt info and outputs to page using <div> tags)

    Even if the post is in the current page or on other page,the page will still refresh if you haven't used AJAX for it.
     
    ryantetek, Feb 17, 2010 IP
  8. Imozeb

    Imozeb Peon

    Messages:
    666
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks, I think I understand.
     
    Imozeb, Feb 18, 2010 IP