I'm using Imagefield with Filefield...

Where can I change the "Add another item" button text? I was searching through the files of both Filefield and Imagefield but could not find it.

Files: 

Comments

I believe FileField lets CCK handle multiple values itself. So CCK sets that button's text, not FileField. I don't know if there is a simple way to change it, since it's set directly in a function content_multiple_value_form(), but somebody else might know more.

Thanks for the tip.

I found the text in cck/includes/content.node_form.inc and changed "item" to "photo" as I wanted.

I'm assuming that won't mess anything up....

I don't see how it would interfere with anything directly (again, someone else might know more about that), but it could complicate upgrades. If CCK releases a new version and you want or need to upgrade, either you'll replace your modified file and need to change it again, or you won't replace it and could break something if the new release has changed something there.

The correct solution would be to form_alter() the node form and the JavaScript callback so that the form element's '#value' property is changed just for the specific field that you target. That would also remove upgrade issues. No, I'm not creating any example code, don't feel like searching and testing all the details.

Status:Active» Closed (fixed)

Status:Closed (fixed)» Active

jpetso,

The form_alter part is not that complex:

<?php
/**
* Implementation of hook_form_alter().
*/
function XXX_form_alter(&$form, $form_state, $form_id) {
  if(
$form['#id'] == 'node-form') {
    if(!isset(
$form['#field_info'])) {
      return;
    }
    foreach(
$form['#field_info'] as $key => $info) {
      if (
$info['type'] == 'XXX') {
       
$form[$key][$key.'_add_more']['#value'] = t('Add another XXX');
       
$form[$key][$key.'_add_more']['#attributes'] = array('class' => 'XXX-add-more');
      }
    }
  }
}
?>

However, can you give me a lead how do I force CCK to use my alter function when creating the AHAH output who could call my JS fix function after the AHAH call?
I couldn't find any usable callback place in ahah.js :-(

Thanks!

Title:Where can "Add another item" text be changed?Allow "Add another item" text be changed.
Project:FileField» Content Construction Kit (CCK)
Version:6.x-3.0-alpha5» 6.x-2.1
Component:Code» Usability
Category:support» feature

I have moved this to the correct place, and chnaged this to a feature request.
Changing the text button should be easier - even if not really exposed via UI.

Please advice.

Try form_alter against the $form_id == 'content_add_more_js'. ;-)

I created a custom module to handle modifications to my node add form. I have a number of CCK fields in this form and it's easy to change the titles/values/etc using:
$form['field_foo']['#title'] = 'my new title';

This does not seem to work for me with the "Add another item" button. I tried:
$form['field_image_add_more']['#value'] = 'Add another image';

Shouldn't this work? Thanks--
pp

Thank you! it works!

<?php

function XXX_form_alter(&$form, $form_state, $form_id) {
  if(
$form['#id'] == 'node-form') {
    if(!isset(
$form['#field_info'])) {
      return;
    }
    foreach(
$form['#field_info'] as $key => $info) {
      if (
$info['type'] == 'XXX' ) {
       
$form[$key][$key.'_add_more']['#value'] = t('Add another XXX');
      }
    }
  }
  if(
$form_id == 'content_add_more_js' ) {
    foreach(
$form as $key => $element) {
      if ( isset(
$element[0]) && isset($element[0]['#type']) && $element[0]['#type'] == 'XXX' ) {
       
$form[$key][$key.'_add_more']['#value'] = t('Add another XXX');
      }
    }
  }
}
?>

:-)

Status:Active» Closed (fixed)

Hi--

Im having trouble implementing this theme override. I have a custom module that themes my custom content type ("products") node form. in my module I have a custom function:

<?php
function ppadd_products_form_alter(&$form, $form_state, $form_id) {
   
//global $user; if ($user->uid==1) drupal_set_message("Form ID: " . $form_id);
 
switch ($form_id) {
    case
'products_node_form':
       
// drupal_set_message('<pre>'. var_export($form,TRUE) .'</pre>');
       
if(!isset($form['#field_info'])) {
          return;
        }
        foreach(
$form['#field_info'] as $key => $info) {
          if (
$info['type'] == 'field_image' ) {
           
$form[$key][$key.'_add_more']['#value'] = t('Add another image');
          }
        }
    break;
  case
'content_add_more.js':
        foreach(
$form as $key => $element) {
          if ( isset(
$element[0]) && isset($element[0]['#type']) && $element[0]['#type'] == 'field_image' ) {
           
$form[$key][$key.'_add_more']['#value'] = t('Add another image');
          }
        }
       
// Print out the $form array to see all the elements we are working with
        // $output .= '<pre>' .print_r($form) . '</pre>';
   
break;
  }
}
?>

This isnt working--is it because I have a distinct case for content_add_more.js? Should this conditional be nested within the other case?

thanks much--
pp

subscribe

This does not seem to work for me with the "Add another item" button. I tried:
$form['field_image_add_more']['#value'] = 'Add another image';

For your example you would need to put:

$form['field_image']['field_image_add_more']['#value'] = 'Add another image';

For your example you would need to put:

$form['field_image']['field_image_add_more']['#value'] = 'Add another image';

Ok with the first item but not with the second and more

(sorry for my english)

have you solutions?

thank

Bastien (france)

#15 is correct--this line of code only changes the button for the first instance of it. Clicking the button provides another button with the original text in the button...any tips?

thx
PP

Hi guys,

Just in case you're still looking for a solution, take a look at this great snippet: http://drupal.org/node/536842. Just need to create a very simple module and add the code to the .module file.

Title:Allow "Add another item" text be changed.Allow "Add another item" text be changed after ahah

I had more luck with this approach. I alter it in the original form and then again I alter it when the form element is recreated in the ahah callback.

<?php
function demolibrary_form_alter(&$form, $form_state, $form_id) {
    if(
$form_id == 'voice_actor_profile_node_form') {
         
$form['field_actor_phone']['field_actor_phone_add_more']['#value'] = 'Add another phone number';
       }
  if(
$form_id == 'content_add_more_js' ) {
      if(isset(
$form['field_actor_phone'])) {
         
$form['field_actor_phone']['field_actor_phone_add_more']['#value'] = 'Add another phone number';
      }
  }
?>

#18 suffers from the issue indicated in #15.

#17 works for me. I tweaked it as follows (and noted in the comments) to only modify the fields I wanted to modify, and to set the replacement text myself (rather than it just replacing the word "item" with the field title):

function _fnfn_helper_node_form_after_build_recursive(&$elements) {
  // added by shiraz
  $replacements = array(
    'field_cis_com_with' => 'Add another person',
    'field_cis_com_with_to' => 'Add another person',
    'field_cis_com_con_prj' => 'Add another related project',
  );   
  foreach (element_children($elements) as $key) {
      if (isset($elements[$key]) && $elements[$key]) {
        if (isset($elements[$key][$key .'_add_more'])) {
          $type_name = $elements[$key][$key .'_add_more']['#type_name'];
          if (isset($elements[$key][$key .'_add_more']['#field_name'])) {
            if (isset($replacements[$key])) {  // added by shiraz
              $elements[$key][$key .'_add_more']['#value'] = t($replacements[$key]); // tweaked by shiraz
            }
          }
<snip>
add an extra } at the end.

StatusFileSize
new3.99 KB

I pilfered much of the contrib code and adapted it a bit to make a simple little module as I know many are intimidated by writing their own module.

The code is basically from http://drupal.org/node/536842 with inspiration from comment #19 so you can put in KISS refers to the your field name, ala:

  // Want to use custom text in your button?
  // Set that below with the key item on the left set to the name of the field
  $replacements = array(
    'Documents' => 'Add another document',
    'External document' => 'Link more external documents',
  );

Anyways, the code is attached and if anyone's feeling inspired all this module needs is a Drupal front end and it could probably be submitted as a project.

And, as always, don't use this on a live site before testing.

Status:Closed (fixed)» Needs review

Setting this to "needs review" to catch a few eyeballs.

Ken,

I am fairly new to Drupal, but I am very interested in this module. Is there any way I can help you test it?

--Brian

+1

Status:Needs review» Reviewed & tested by the community

@Ken: I love your module, it works perfectly. It would be awesome if you (or someone else?) could add a config screen where you could change the custom text in Drupal, rather than editing the .module file directly, but I love it as-is.

I'm marking this "tested by the community" because it is. I think this module is ready for inclusion in CCK. I'd also love to see it ported to D7.

@koppie: I'm still doing much learning in the realm of drupal module development — it will likely be a month or two before I'm feeling confident enough/have time to make this a full-fledged enough module to consider submitting it. That said, perhaps I should look into starting up my own sandbox module.

**UPDATE** Well that wash't too bad. The sandbox module lives at http://drupal.org/sandbox/khawkins98/1266386 and the dev code at https://github.com/khawkins98/cck_tweak_button

You can also do this in D7 by using hook_form_FORM_ID_alter in your module. Example:

function hook_form_FORM_ID_alter(&$form, &$form_state) {
  $form['your_field_here'][LANGUAGE_NONE]['add_more']['#value'] = t('Your custom text here');
}