This is the documentation for LemonStand V1, which has been discontinued. You can learn more and upgrade your store here.

LemonStand Version 1 Has Been Discontinued

This documentation is for LemonStand Version 1. LemonStand is now offered as a cloud-based eCommerce platform.
You can try the new LemonStand and learn about upgrading here.

Adding the comment form

The blog comment form allows website visitors to specify the following data along with a comment itself: author name, email address, website URL. On the Blog/Settings page in the Administration Area you can specify whether the author name and email address are required. Also, you can implement a checkbox allowing your visitors to subscribe to new comments email notification.

In this example we will demonstrate the AJAX implementation of the post comment form. To enable the LemonStand AJAX framework you need to include LemonStand JavaScript libraries in the HEAD section of your page or template:

<head>
  ...
  <?= $this->js_combine(array(
  'mootools',
  'ls_core_mootools')) ?>
  
  <?= $this->css_combine(array('ls_styles')) ?>
  ...
</head>

The AJAX implementation requires the comment form to be created as a separate partial. Create a new partial and assign it some name, for example "blog_comment_form". Below is an example code of the comment form, which you can use in the comment form partial:

<? if (!isset($comment_success) || !$comment_success): ?>
  <?= open_form() ?>
  <label for="author_name">Name</label>           
  <input id="author_name" type="text" name="author_name"/><br/>

  <label for="author_email">Email</label>
  <input type="text" id="author_email" name="author_email"/><br/>

  <label for="author_url">Website URL</label>
  <input type="text" id="author_url" name="author_url"/><br/>

  <label for="comment_content">Comment</label>
  <textarea id="comment_content" name="content"></textarea><br/>

  <label for="subscribe_to_notifications">Notify me if someone else comments on this post</label>
  <input type="checkbox"
    id="subscribe_to_notifications" 
    name="subscribe_to_notifications" value="1"/><br/>

  <input type="submit" value="Post Comment" onclick="return $(this).getForm().sendRequest(
    'blog:on_postComment', 
    {update: {'comment_form': 'blog_comment_form'}})"/>
  </form>
<? else: ?>
  <p>Your comment has been posted. Thank you!</p>
<? endif ?>

The $comment_success variable is created automatically by the Blog module and will have the TRUE value in case of successful comment sending. The Post Comment button triggers the blog:on_postComment AJAX event handler, which is defined in the Blog module. In the update parameter of the AJAX request we specified that the comment form partial name is blog_comment_form. If your partial name is other, you need to specify it in the code. Also the update parameter specifies that the comment form partial should be rendered inside a page element with the comment_form identifier. We need to create such element on the blog post page and render the form partial inside:

<? if ($post->comments_allowed): ?>
  <div id="comment_form">
    <? $this->render_partial('blog_comment_form') ?>
  </div>
<? endif ?>

Next: Implementing RSS channels
Previous: Blog post page
Return to Blog module