=== Ajax Comment Posting === Contributors: regua Tags: comments, ajax, post, comment Requires at least: 1.5.2 Tested up to: 2.2.3 Stable tag: 1.1 Posts comments without refreshing the page and validates the comment form using Ajax. == Description == There are many comment-related plugins in Wordpress plugin directory. However, if you'd like to find just a simple comment-posting Ajax plugin, you won't find any. That's why I developed a simple yet functional Ajax Comment Posting (ACP) plugin. Not only will it post your comment without refreshing the page, but it will also make sure that you've filled all the form fields correctly. The plugin works well in all major Web browsers, and switches to the traditional comment posting if JavaScript is disabled. ACP should work with all CAPTCHA word-verification plugins, but I personally suggest using [Akismet](http://codex.wordpress.org/Akismet "The Akismet anti-spam plugin"). You can easily add some more functionality to your comment form using [jQuery](http://jquery.com "The jQuery JavaScript framework"), the best JavaScript framework, which is used by ACP to handle the Ajax requests and all those fancy fade-in/out effects. == Installation == 1. Upload the plugin directory `ajax-comment-posting` to the `wp-content/plugins` directory. 2. Activate the plugin through the 'Plugins' menu in WordPress. == Frequently Asked Questions == = Why isn't my plugin working or it works differently than it should? = It's probably your WordPress theme's fault. ACP needs several things to be present in your comments.php file (in the theme's default directory). The submit button has to have a submit id, the comment form has to have a commentform id, the ol (or div, whatever) with the comments has to have a commentlist class, the comment form's header (or some other header/div/span you want to display the success message in) must have respond id set, and the 'log out' link has to have a Log out of this account title set (it's a simple way to check whether the user is logged in or not; it's done this way because of the lack of PHP in .js files). Also, make sure that the following code is present somewhere in the head (header.php) section of your theme: <?php wp_head(); ?> Most WordPress themes meet these requirements. If yours doesn't - please let me know. = How can I customise the look of the error and success messages? = You can either change the acp.css file in the plugins directory, or just delete the file and add error and success classes to your CSS stylesheet. = How can I change or remove the loading icon? = The loading icon is the file loading.gif inside ACP's directory. If you want to remove the icon, just delete the icon image file and you'll get a 'Loading...' message instead. = Why does the comment form disappear after a comment is added? = For security reasons. Usually users dont want to post two comments in a row, so whats the reason in leaving the form there? If you still want to keep it from being removed, delete the line 56 in acp.js file. = How does the plugin work? = First, it validates the form - checks if you've enter a name, (valid) email address and the comment (if you're a logged-in user, you don't have to enter the name and email, of course). Then it submits the form using Ajax (Asynchronous JavaScript and XML), then checks whether the server returned an element with "commentlist" class. If not, this means that an error has occured; thus, it checks if the response contains any paragraphs (the error page in WP 1.5.2 is just plain text) and then displays the error message in the #error div. The whole validation process could've been done in simple JavaScript, but there are some erros (e.g. 'duplicate comment' and 'comment sent too fast') which would be difficult to validate on the client-side, so I decided to let WordPress do the validation and just get the result. When the script submits or receives any data, the loading icon is shown. Also, after a successful submition, it removes the comment form (see the question above if you want to prevent this from happening) and displays a nice, green-coloured message. [Contact me](http://regua.biz/contact "Contact the author of the plugin") if you have any questions, bug reports or suggestions. == Screenshots == Visit [the plugin page](http://regua.biz/acp "The ACP page") to see some screenshots.