SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help me with my email form

    I have an email form in my index.html that post to a file called process.php.

    Is it possible to have my form disappear after submit and "your information has been sent" to be shown on the page where the form was without changing th index to a php?

  2. #2
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    323
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Yep, look into AJAX.

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Create a javascript function which sends an AJAX post request to a php file, setting the name and value to the names and values of the form data. It should also add a new value, 'isAjax' and set that to 1 - but don't have this in the form.

    The process.php file should then send off the email. If $_POST['isAjax'] is set and equals 1, then echo 1 for email success, 0 for failure. Otherwise, display a page with either a success message or the error and telling them to click 'back' and try again.

    The JS function should pick up the value received (1 or 0) and set the innerHTML of a <div> tag to a suitable message depending on the value.

    In the form, set the form's onsubmit property to the function, and then return false.

    That way, if the user doesn't have JS enabled (and there are quite alot) then they will be sent to process.php, which gives them a suitable method. If they do have JS enabled, they will see that it was sent or not by a message in the chosen element.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


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
  •