Learn how to AJAXify your Comment Forms
videos

Learn how to AJAXify Comment Forms

In this week’s video tutorial, I’ll teach you how to take a simple, boring contact form and add some animations and an AJAX post request to submit the form to your MySQL database asynchronously.

In addition, we’ll also implement a bit of server and client-side validation to better secure our data. When submitting to the database, we’ll also review the most secure methods, including the use of prepared statements, which will bind the necessary values to each query, rather than embed them.

Screencast

*Note – please forgive me, but I had a slight cold when recording this. I apologize if my words are a bit mumbled.

Other Viewing Options

Conclusion

Example

This screencast demonstrated just one way to animate your contact forms. Truthfully, it’s probably a bit too much for a regular site! :) But we’re here to have fun with it. If you decide to implement something like this into your own site, perhaps a more toned down version, please do leave a comment with a link to the page for our review!


Add Comment

Discussion 100 Comments

Comment Page 2 of 2 1 2
  1. ganesh says:

    I tried it out and works great in my site, http://bit.ly/7VLXdc

  2. Black says:

    I always get this error:

    Fatal error: Cannot instantiate non-existent class: mysqli in /home/www/web372/html/comment/getItemsFromDatabase.php on line 5

    help PLEASE!

  3. Tom says:

    Please help!

    I followed up this tutorial step by step and I cannot add any comment to my database. I can retrieve information from database, but I cannot add anything.
    I am not getting any errors or warnings.
    I reviewed day11 of ‘diving into php’ and everything works fine. I can either add or get info from database. In this case when I click on ‘Post comment’ with filled form nothing happens, no information is added to the database.
    The code I used is exactly the same as Jeffrey did. The database has been also created the same way.
    Please help!

  4. Tyler Spears says:

    How do I this to an existing webpage, like the comment section this is in?
    Thanks

  5. Sinfonia says:

    That’s so cool I was looking for comments HTML and I found more here .

    Thanx :)

  6. Per Wikman says:

    Great tutorial, but what about escaping html entities? If you type say alert(‘hello world’) in the name field, that script is going to run on the site. Of course, if you’ve escaped it with php then it shouldn’t be a major problem and the rest of the site won’t be affected. Yet it is slightly unsettling to let it slip by. Any fix for that?

  7. Daniel says:

    Great tutorial, but i´ve this problem. Please helpme!

    Warning: Cannot modify header information – headers already sent by (output started at /home/name/public_html/ajaxComment/leaveComment.php:21) in /home/name/public_html/ajaxComment/leaveComment.php on line 24

  8. Harfleur says:

    This is really useful, thanks!

  9. hiuyu says:

    how can the newest post appears at the top after submit?
    how can it support input in CHINESE name in the name area?

  10. Lash says:

    Hello very nice the tutorial but I have a problem

    When I login to comment this page I load in the commentary,
    if you could see my page to see what I’m talking and I can help.

    thanks

  11. Level Switch says:

    This is nice and very interesting. Instant feedback mechanisms do take out a lot of pain from the contact forms.

  12. ken says:

    nice one

  13. fake oakley says:

    Instant feedback mechanisms do take out a lot of pain from the contact forms.

  14. malik says:

    how to add an comment box in a non uploaded website, i mean for a nonpurchased domain.

  15. Leandro says:

    Muito Bom!!

  16. Edgar Lopez says:

    Ican’t see the screencast???

    Help a tried in all my explorers: firefox, chrome, opera and even IE

Comment Page 2 of 2 1 2

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.