I have a mytheme_comment_form(&$form) function to make some modifications to the comments form on my site. However when I change the value of the 'submit' item, like this $form['submit']['#value'] = 'Post comment';, the comment no longer submits, it just refreshes the current page as opposed to sumitting the comment and redirecting back to the node like it should.

Any ideas why this is happening?

Comments

ltwinner’s picture

Here's my preprocess_comment_form function -

function betsnipers_comment_form(&$form){

  unset($form['_author']);
  unset($form['author']);
  unset($form['subject']);
  unset($form['comment_filter']['format']);
  unset($form['preview']);
  unset($form['comment_filter']['comment']['#title']);

  $form['submit']['#value'] = 'Post comment';
  
  return drupal_render($form);
}

If I remove the $form['submit']['#value'] = 'Post comment'; it submits properly. Anybody got any ideas?

fiasst-1’s picture

$form['submit']['#value'] = "New Submit Value";
unset($form['submit']['#name']);
$form['op'] = array(
	'#type' => "hidden",
	'#name' => "op",
	'#value' => "Post comment",
);

Wow, I answered something for once on drupal forums! Wooo! (hope Im right now...)

;]

clockwood’s picture

I'm getting the same problem using similar code. When I submit the form, it takes me to "/comment/reply/nid".

<?php
function epi_theme() {
	return array(
		'comment_form' => array(
		'arguments' => array('form' => array()),
		),
	);
}

function epi_comment_form($form) {
	unset($form['subject']);
	$form['submit']['#value'] = t('Post Comment');

	return (drupal_render($form));
}
?>

Also like the OP, if i remove $form['submit']['#value'] = t('Post Comment'); it works normally.

Tried the suggestion above, but it doesn't work.

karhidle’s picture

did you find a solution for this? i'm having the exact same problem

clockwood’s picture

Nope, sorry.

daniel wentsch’s picture

Has somebody found a solution for this in the meantime?

mattwmc’s picture

I used this mod to change the 'Save' button text to 'Submit' - http://drupal.org/project/stringoverrides

However, this might be site wide.

daniel wentsch’s picture

Thanks for answering, but I guess this would change all submit buttons, not only those on comment forms, right?

I solved the problem by writing a mini module implementing hook_form_alter() to get specifically the string of the comment form submit button altered:

<?php
function commentsubmit_form_alter(&$form, $form_state, $form_id) {
  if($form_id == 'comment_form') {
    $form['submit']['#value'] = t('Add comment');
  }
}

?>
skizzo’s picture

nodeformsettings allows you to change Submit (and much more) on Nodes and/or Comments on per-ContentType basis. May be overkill if your needs are very specific.

beauz’s picture

Is this a bug?

Surely this seems like the logical way to do this. But I'm having this problem as well now and it seems many others are too.

dodorama’s picture

I'm experiencing exactly the same. It sounds like a bug.

morthylla’s picture

When you click a button, the browser sends its name and value back to the server so that the script running there know which button was pressed. For example, if you click the "Preview" button, your Drupal module would see op=Preview and know you want to preview the form.

The notorious "Form API" too see this the "op=" parameter. In order to decide which button was pressed, it compares this 'op' against the '#value's of all the buttons in the $form array.

Now,

The problem is that the Form API is oblivious to anything you do in the theming phase. This phase is carried out after the Form API has finished its working. So you change the label of the button there, but only your browser sees this change. When Form API sees the "op=My Modified Label" the browser sends it doesn't know which button this label belongs to. It never see a button with such label. The theming phase is too late a place for changing button labels (but not for changing labels of almost anything else).

I copied this from https://drupal.org/node/140387 where mooffie explained that the right way to change text buttons is with form_alter, inside a module.

Cheers

hubertusanton’s picture

For comment forms this seems to work in template.php

function [theme_name]_comment_form($form) {

  $form['submit']['#value'] = "Send it!";
  unset($form['submit']['#name']);
  $form['op'] = array(
    '#type' => "hidden",
    '#name' => "op",
    '#value' => t('Save')

);
jchandra’s picture

I know this is an old thread, but I was having the same problem and this solution worked for me.