SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    stopping html page from directing to the php file

    hello, i have a html page which is used to add a new user to the system, the details input are sent via the form to a php file.
    when any of the details entered are incorrect error messages show up.
    however i do not want the html page to change but it does.

    so basically I have a html file with a form the form posts the input data from textfields to the php file.

    I need the html page to stay as it is with what ever data the user has entered but instead the page changes to the php file location because the data is being posted to this php file.

    i am assuming this may need some javascript to make keep the page from changing. i have tried self.location "" but it does not do what i need it to.

    please someone help me resolve this issue.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Since PHP files can output HTML markup, you could have the form be in a PHP file that submits to itself, handling any POST variables and doing whatever (if all "good", enter into db, sent in an email, use the "good" input values to populate the form again using a message for the "bad" input, etc.).

    If the POST variables are sent to a different (PHP) file, you could do the stuff and then use header() to go back to the submitting form.

    Or you could use AJAX to process the inputs as the get filled in, and not let the form be submitted until everything's OK (assuming javascript is enabled).

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi i would like to take the AJAX approach but i am not familer with it, would you please give me some guidance.

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    I haven't done much AJAX stuff yet. But you would need to do something like:

    Assign event handlers to the inputs (onblur ?).
    Send the XMLHttpRequest to the PHP file with the input's value.
    After the PHP file does it's thing, send the response back.
    Use AJAX to get the response and act accordingly. i.e. Have javascript display an error message and refocus the input if something's wrong with it.

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi there, is there a tutorial or some code u could direct me to as an example

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,269
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    I haven't checked any of these so I can't recommend one over the other. http://www.google.com/search?hl=en&c...on&btnG=Search

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    This is what you need.
    http://bulletproofajax.com/code/

    The Bulletproof Ajax book is pretty good too.
    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
  •