Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By tflmike on
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
Perform alterations before the form is rendered
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.
dropcube- Thanks for the
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:
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!
Ok.... now I see what I was
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!
Put like this
hook_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'coment_form') {
$form['#action'] = url('virtualgrave/result');
}
}
Did you ever find a solucion
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?
I can see my messages when the form show up.