protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $isNew = $form->getObject()->isNew();
      $notice = $isNew ? 'Your reply was saved successfully.' : 'The item was updated successfully.';

      $sf_nested_comment = $form->save();

      $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $sf_nested_comment)));
      
      $email_pref = sfNestedCommentConfig::isMailEnabled();
      $enable_mail_alert = $email_pref === true || $email_pref == 'moderated';

      if ($isNew && $enable_mail_alert && $sf_nested_comment->isReply())
      {
        $userComment = $sf_nested_comment->getsfNestedCommentRelatedBySfCommentId();
        $params = $this->prepareMailParameter($sf_nested_comment, $userComment);
        sfNestedCommentTools::sendEmail($this->getMailer(), $params);
      }
      
      $this->getUser()->setFlash('notice', $notice);
      $this->redirect('@sf_nested_comment');
    }
    else
    {
      $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
    }
  }
  public function executeAddComment(sfWebRequest $request)
  {
    $this->commentForm = new sfNestedCommentFrontForm(null, $this->getUser());
    $bindValues = $request->getParameter($this->commentForm->getName());
    if (sfNestedCommentConfig::isRecaptchaEnabled())
    {
      $captcha = array(
        'recaptcha_challenge_field' => $request->getParameter('recaptcha_challenge_field'),
        'recaptcha_response_field'  => $request->getParameter('recaptcha_response_field'),
      );
      $bindValues = array_merge($bindValues, array('captcha' => $captcha));
    }
    $this->commentForm->bind($bindValues);
    if ($this->commentForm->isValid())
    {
      $comment = $this->commentForm->save();

      $this->getUser()->setFlash('add_comment', $comment->getIsModerated() ? 'moderated' : 'normal');
      
      $this->dispatcher->notify(new sfEvent($this, 'sf_nested_comment.add', array('object' => $comment)));

      $email_pref = sfNestedCommentConfig::isMailEnabled();
      if($email_pref == true || ($email_pref == 'moderated' && $comment->getIsModerated()))
      {
        $params = $this->prepareMailParameter($comment);
        sfNestedCommentTools::sendEmail($this->getMailer(), $params);
      }

      if($request->isXmlHttpRequest())
      {
        $this->setLayout(false);
        sfConfig::set('sf_web_debug', false);
        $commentableObject = $comment->getCommentableObject();
        $comments = sfNestedCommentTools::getComments($commentableObject, $request);
        return $this->renderPartial('sfNestedComment/comments', array('object' => $commentableObject, 'comments' => $comments, 'commentForm' =>  sfNestedCommentTools::createCommentForm($commentableObject)));
      }
      else
      {
        return $this->redirect($request->getReferer());
      }
    }
    else
    {
      if($request->isXmlHttpRequest())
      {
        $this->getResponse()->setStatusCode(404);
        $this->setLayout(false);
        sfConfig::set('sf_web_debug', false);
        return $this->renderPartial('sfNestedComment/add_comment', array('commentForm' => $this->commentForm));
      }
      else
      {
        return 'Error';
      }
    }
  }