Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other How to make Chris’s contact form ajax?

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #43304
    AlirezaM
    Participant

    Hello!

    I want to use Chris’s contact form in my website but I want it to not refresh the page when I click on submitt button.

    Is there anyway to make it ajax to work this way?

    If yes how?

    Thanks in advance!

    Alireza.M

    #127755
    CrocoDillon
    Participant

    I don’t know what you mean by Chris’ contact form but sure you can use JavaScript to intercept the form submit and then submit it using AJAX instead, prevent it’s default behavior and wait for the response to update the page.

    With jQuery it would be something like:

    $(‘#form_id’).submit(function() {
    // prevent default
    // make AJAX call, sending form values
    // update page on complete
    });

    #127785
    Eric
    Member

    Pretty sure there is more to it than that. Here is how I put it all together. It was not easy. http://www.websitecodetutorials.com/code/jquery-plugins/jquery-ajaxsubmit.php

    #127789
    CrocoDillon
    Participant

    Pretty sure there isn’t: http://crocodillon.com/temp/ajaxform.html

    #127847
    Eric
    Member

    @CrocoDillon nice. But you cant use php validation with that right?

    #127849
    CrocoDillon
    Participant

    Sure you can, the php file I have is really simple (for demo only) but you can do everything with the POST data you want.

    echo ‘Hello there, ‘.htmlspecialchars($_POST).’!’;
    else
    echo ‘Hello there, Mr. Smith!’;

    Don’t mind me sending html back though, XML or JSON would probably be better (if you want to give feedback on validation errors).

    #127856
    Eric
    Member

    cool – cool. I stand corrected. :)

    #127864
    CrocoDillon
    Participant

    :)

    #128450
    AlirezaM
    Participant

    Thank you CorocoDillon!

    It worked as it was in my mind.

    Thanks again!

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Other’ is closed to new topics and replies.