You are here

function ajax_comments_form_alter in AJAX Comments 5

File

./ajax_comments.module, line 4

Code

function ajax_comments_form_alter($form_id, &$form) {
  if ($form_id == 'comment_form' && arg(1) != 'edit') {
    $form['#prefix'] = '<div id="comment-preview"></div>';
    $form['js_enabled'] = array(
      '#type' => 'hidden',
      '#default_value' => $_GET['q'],
      '#weight' => 0,
    );
    $form['#suffix'] = '<script>$("#comment-form #edit-js-enabled").val(1);</script>';
    if (!empty($_POST) && $_POST['form_id'] == $form_id) {

      // Redirect on successful submit, i.e., if there are no errors.

      //print_r($form);
      if (is_array($form['#pre_render'])) {
        $form['#pre_render'][] = 'ajax_comments_dispatch';
      }
      else {
        $form['#pre_render'] = array(
          'ajax_comments_dispatch',
        );
      }
    }
    $form['#submit'] = array(
      'ajax_comments_submit_dispatch' => array(),
    );
    jquery_form_add();
    $path = drupal_get_path('module', 'ajax_comments');
    drupal_add_js($path . '/ajax_comments.js', 'module');
    drupal_add_css($path . '/ajax_comments.css');
    drupal_add_js(array(
      'ajax_comments_form_alter' => array(
        'cleanurls' => (bool) variable_get('clean_url', '0'),
        'basePath' => base_path(),
      ),
    ), 'setting');
  }
}