Hello everyone,

I have been doing some research into changing the save button on my drupal forums to display post instead. I have gotten a lot of feedback from my website requesting this. The best fix I have currently found is to create a new module that does this. I grabbed someones code from a suggestion a few years ago that seems to work for most but not me. I am not sure if the code or the way I created the .info and .module is incorrect. Any suggestions are welcome!

change_forum_values.info

name = Change Forum Value
description = Changes the save button to post button.
core = 7.x

change_forum_values.module

<?php

function change_form_values_form_alter(&$form, &$form_state, $form_id) {
    //dsm($form_id); // to see form ID
    if ($form_id == "content_type_test_node_form") {
    $form['actions']['submit']['#value'] = 'Post';
    }
}

I have the module enabled but it is still showing save for my forums.

Comments

VM’s picture

psssst. There's already a module for that @ https://www.drupal.org/project/node_buttons_edit

haxanator’s picture

This worked for the initial post but when replying to someones topic it still says "save".

http://retrogamer.us/node/210 to see my issue.

jaffaralia’s picture

You have to include comment form id also.. So that it will change the label in comment form also.

Here is the example


function change_forum_values_form_alter(&$form, &$form_state, $form_id) {
    //dsm($form_id); // to see form ID
    if ($form_id == "content_type_test_node_form"  || $form_id == "comment_node_forum_form") {
    $form['actions']['submit']['#value'] = 'Post';
    }
}
haxanator’s picture

I went with the module already created as mine would not work. I am looking for a similar section for your modification but don't see one. Any suggestions on where I can add your fix?

<?php
/**
 * @file
 *   The the node buttons edit module.
 */


/**
 * Implements hook_form_FORM_ID_alter().
 */
function node_buttons_edit_form_node_type_form_alter(&$form, &$form_state, $form_id) {
  $node_type = isset($form['#node_type']->type) ? $form['#node_type']->type : '';
  
  $form['submission']['buttons'] = array(
    '#type' => 'fieldset',
    '#title' => t('Submission buttons'),
  );

  $form['submission']['buttons']['node_buttons_edit_save_new'] = array(
    '#type' => 'textfield',
    '#title' => t('Save button text (on adding)'),
    '#default_value' => variable_get('node_buttons_edit_save_new_' . $node_type, 'Save'),
  );
  
  $form['submission']['buttons']['node_buttons_edit_save_edit'] = array(
    '#type' => 'textfield',
    '#title' => t('Save button text (on editing)'),
    '#default_value' => variable_get('node_buttons_edit_save_edit_' . $node_type, 'Save'),
  );
  
  $form['submission']['buttons']['node_buttons_edit_preview_new'] = array(
    '#type' => 'textfield',
    '#title' => t('Preview button text (on adding)'),
    '#default_value' => variable_get('node_buttons_edit_preview_new_' . $node_type, 'Preview'),
  );
  
  $form['submission']['buttons']['node_buttons_edit_preview_edit'] = array(
    '#type' => 'textfield',
    '#title' => t('Preview button text (on editing)'),
    '#default_value' => variable_get('node_buttons_edit_preview_edit_' . $node_type, 'Preview'),
  );
  
  $form['submission']['buttons']['node_buttons_edit_delete_edit'] = array(
    '#type' => 'textfield',
    '#title' => t('Delete button text (on editing)'),
    '#default_value' => variable_get('node_buttons_edit_delete_edit_' . $node_type, 'Delete'),
  );
}

/**
 * Implements hook_form_FORM_ID_alter().
 */
function node_buttons_edit_form_node_form_alter(&$form, &$form_state, $form_id) {
  $node_type = $form['#node']->type;

  if (empty($form['#node']->nid)) {
    $form['actions']['submit']['#value'] = variable_get('node_buttons_edit_save_new_' . $node_type, 'Save');
    $form['actions']['preview']['#value'] = variable_get('node_buttons_edit_preview_new_' . $node_type, 'Preview');
  }
  else {
    $form['actions']['submit']['#value'] = variable_get('node_buttons_edit_save_edit_' . $node_type, 'Save');
    $form['actions']['preview']['#value'] = variable_get('node_buttons_edit_preview_edit_' . $node_type, 'Preview');
    $form['actions']['delete']['#value'] = variable_get('node_buttons_edit_delete_edit_' . $node_type, 'Delete');
  }
}

/**
 * Implements hook_variable_info().
 */
function node_buttons_edit_variable_info($options) {
  $variables['node_buttons_edit_save_new_[node_type]'] = array(
    'type' => 'multiple',
    'title' => t('Save button title on new content', array(), $options),
    'repeat' => array(
      'type' => 'string',
      'default' => 'Save',
    ),
  );

  $variables['node_buttons_edit_preview_new_[node_type]'] = array(
    'type' => 'multiple',
    'title' => t('Preview button title on new content', array(), $options),
    'repeat' => array(
      'type' => 'string',
      'default' => 'Preview',
    ),
  );

  $variables['node_buttons_edit_save_edit_[node_type]'] = array(
    'type' => 'multiple',
    'title' => t('Save button title on existing content', array(), $options),
    'repeat' => array(
      'type' => 'string',
      'default' => 'Save',
    ),
  );

  $variables['node_buttons_edit_preview_edit_[node_type]'] = array(
    'type' => 'multiple',
    'title' => t('Preview button title on existing content', array(), $options),
    'repeat' => array(
      'type' => 'string',
      'default' => 'Preview',
    ),
  );

  $variables['node_buttons_edit_delete_edit_[node_type]'] = array(
    'type' => 'multiple',
    'title' => t('Delete button title on content', array(), $options),
    'repeat' => array(
      'type' => 'string',
      'default' => 'Delete',
    ),
  );

  return $variables;
}
VM’s picture

The link doesn't aid as I don't have a user on your site so I don't see the button you are referring to. first thing I'd do is check the issue queue of the module in use. Seems to me that the comment buttons would be a common want.

VM’s picture