I'm trying to get my code for my comment form to work and I noticed that $form['action'] is set to the correct url. So I tried to used the following code in my form override (in template.php):

/**
 * Theme the comment_form!
 *
 */
 function phptemplate_comment_form($form) {
 $output = '';
 
 $form['#action'] = url('/comment/reply/test' .$nid); /* THIS CODE DOESN"T SEEM TO WORK */
 
 unset($form['_author']);
 unset($form['author']);
 unset($form['comment_filter']['comment']['#title']);
 unset($form['comment_filter']['format']);

 $output .= '<div class="comment-form">';
 $output .= '<div class="commentLabelBox">';
 $output .= 'Leave a comment:';
 $output .= '</div>';
 
 $output .= '<div class="commentText">';
 $output .= drupal_render($form['comment_filter']['comment']);
 $output .= '</div>';
 
 $output .= '<div class="commentBTNS">';
 $output .= drupal_render($form['preview']);
 $output .= drupal_render($form['submit']);
 $output .= '</div>';
 
 $output .= drupal_render($form);
 $output .= '</div>';
 
 return $output;
 
 }

So I've tried a number of different ways to get $form['#action'] set but it doesn't seem to 'take'. Can anyone shed some light on why this isn't working?

Thanks so much!

Comments

dropcube’s picture

Don't do this at the theme level. Create a custom module that implement hook_form_alter and perform alterations before the form is rendered.

tflmike’s picture

dropcube-

Thanks for the reply! I've been trying to get this to work in the module level, but Idon't think I'm using hook_form_alter correctly. I've installed my module and I added some simple code just to see if I can get it to work but I'm doing something wrong. Here's the code I've been messing with:

  function modulename_form_alter($form_id, &$form) {
    // A switch is used because you may want to alter more than
    // one form and it is easy to add a new case for each form.
    switch ($form_id) {
      // This is our form ID.
      case 'comment_form':
        // Our kickin' mods go here.
		$form['#action'] = '/comment/reply/test' .$nid;
        break;
  }
}

I got this code from a Lullabot article (http://www.lullabot.com/articles/modifying-forms-5-and-6) but it doesn't work like they say!

Any thoughts?

Thanks very much!

tflmike’s picture

Ok.... now I see what I was doing. I basically had the wrong function name. So now I've got the function/module/form_alter working.... but when I try to post a comment I still get a 'page not found' error.

Does anyone know what the prober URL is suppose to look like when you preview a comment and when you post a comment? Is it something like: http://mydomain.com/comment/reply/$nid#$cid?

Thanks!

mehuls’s picture

hook_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'coment_form') {
$form['#action'] = url('virtualgrave/result');
}
}

josepvalls’s picture

Did you ever find a solucion for this?
I come from a securepages issue and same thing seems to be happening.

Doesn't work for me, the #action is always the old relative action.
I even tried the following code in my own module.

What am I doing wrong? Something in the configuration?
Is there something overwritting my action? I had login toboggan but it's disabled now.
Do I need to trigger the form rendering again after setting #action? In this case, how do I do this?

function tests_form_alter(&$form, $form_state, $form_id) {
drupal_set_message('alter','info');
   if($form_id == 'user_login_block' || $form_id == 'user_login') {
    $form['#action'] = 'https://www.mydomain.com/mydirectory' . $form['#action'];
    drupal_set_message('alter login','info');
   }
}

I can see my messages when the form show up.