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 atreus on
This is a question about Drupal 6.6. I created a new content type, and would like to change the "save" button to say something different. How difficult would this be?
Would it be possible to change it just for a specific content type?
Andrew
Comments
I guess, you may achieve
I guess, you may achieve this by
1. implement a hook_form and change the title of the submit button.
2. take a look at hook_nodeapi.
The code should be very short in both these cases. For doing it just for one content type, you need to check the form id and parameters or node type respectively.
--------------------------------------------------------------
My attempt with Drupal - Jaanlo.com
Where do hooks go?
Ok, from a bit of googling it doesn't look....too hard. Would I have to create my own module to implement a hook?
Yes
Have a look at the examples on http://api.drupal.org/ these are a great resource.
You could always hack another module, but when you forget about it and upgrade that module, your changes are lost.
Alan Davison
www.caignwebs.com.au
Alan Davison
Hi Atreus, Did you ever come
Hi Atreus,
Did you ever come up with the code for this? I'm really in need of it! If you could post it - would be fantastic... and save me a long time trying to work it out myself with my limited PHP knowledge!
Thanks,
Adam
I have also been working on
I have also been working on this for a couple of days now and have decided to go the module route.
1) Create a .module and .info file (you can learn how to do this here: http://drupal.org/node/206753)
2) From my research it looks like the hook_form_FORM_ID_alter (http://api.drupal.org/api/function/hook_form_FORM_ID_alter/6) would be better to use than the typical hook_form_alter. That way you can just affect 1 form instead of globally.
The code part is what I am having problems with. Being a PHP noob also, I am struggling with syntax.
Here is what I have (doesn't work currently)
As you can see I tried both the commented and uncommented code above but neither work. So unfortunately this is not your answer but hopefully it points you in the right direction and maybe someone with more experience than I can chime in and help us both with what I am missing.
Update
So I changed it to this:
Now, it actually adds ANOTHER submit button (at the very top of the form instead of the bottom next to the existing submit button) with "Save and add new" as the text instead of just replacing the current submit button text. So it appears my code is adding new instead of modifying the existing one. I am getting closer!
I tried viewing source of the page and getting the id of the current submit button and doing something like:
$form['edit-submit']['#value'] = t('Save and add new');
but that didn't work either...
Anyone want to tell me what I am doing wrong?
TIA
Almost :)
Try
<?php $form['buttons']['submit']['#value'] = t('Save and add new'); ?>
Alan Davison
www.caignwebs.com.au
Alan Davison
SWEEEET
Thanks Alan!
I still dont understand how it knows to change the text on that specific button without supplying some sort of ID, but heck it works and I am happy about that!
I mean, if there was a Save and Edit and cancel button, i am guessing they have different IDs?
Thanks again ~
Yep
If you have a look at the native node form:
You can see how they are created. All ids get "edit-" added and underscores are converted to dashes during the theming stage after form alter.
:)
Alan Davison
www.caignwebs.com.au
Alan Davison
Thanks again
for the explanation....
:)
Changing also button action?
Read this interesting tread.
I woult like to change the preview into a Logout button.
Strubbling around the idee came up that the action after pressing a buttons seems to be in the form array (button array) to.
So was thinking the next could work, but didn't:
// cange the button caption
$form['buttons']['preview']['#value'] = t('LogOut');
// change the button action
$form['buttons']['preview']['#submit']['0'] = t('user_logout()');
Is this possible or am i thinking in a rong direction.
Thanks in advance
W!m
Open University of the Netherlands (www.ou.nl)
You could
You could try:
$form['buttons']['preview']['#value'] = t('LogOut');
$form['buttons']['preview']['#submit'] = array('my_logout');
and define the submit callback
function my_logout() {
drupal_goto('logout');
}
The problem with "$form['buttons']['preview']['#submit']['0'] = t('user_logout()');" is:
a) you should not use the brackets or t function (just "$form['buttons']['preview']['#submit']['0'] = 'user_logout';")
b) there is the potential for multiple submit handlers, so rather than [0] and overriding the first, fully overwrite, "$form['buttons']['preview']['#submit'] = array('user_logout');"
c) Lastly, the function 'user_logout' is not included in a *.module and needs to be included. So rather than including the file and calling it directly, I simply used drupal_goto to let drupal do this for me, by calling the menu callback
Sorry for more info than required, but each point may help you in the future.
Alan Davison
www.caignwebs.com.au
Alan Davison
I'm sitting here trying to
I'm sitting here trying to the same thing as these other guys and I'm getting nothing. Here's my function from my submit_button.module:
I'm assuming that it has something to do with either the function name or the case in the switch statement. Thanks for your help!
--amariotti
Put in some debugging
Put in some debugging steps:
And is your module called "submit_button"?
Alan Davison
Yeah. I figured out where my
Yeah.
I figured out where my problem was. His "case my_new_form_node_form" was for his "my_new_form" content type (strange content type, actually).
I changed it to resume_node_form and it works. Now I can customize it on a per content type basis, which is exactly what I wanted from the beginning. Thanks for your help on this discussion.
thanks
thanks alan that worked for me
Alan, nice solution, thanks!
Alan, nice solution, thanks!
Easier ... WAY easier
If you want to change it throughout the site, check out:
http://drupal.org/project/stringoverrides
This was the easiest mod I've ever used. I hid the "preview" button with CSS, then substituted "Submit" for "Save" using String Overrides.
yea but if you want different
yea but if you want different name for button for different form.. that isnt possible with that module
Another global method
Rather than adding a module for this, you can update the strings in the settings.php. Look at the instructions in the settings.php file towards the bottom. As a general rule, less modules == less general overhead, which is always good :)
Alan Davison
This doesn't help if you only
This doesn't help if you only want to change the value given to buttons. You still need the function shown above (in previous posts). I'm thankful to the community for actively supporting common problems and solving most of them. I had forgotten how to get button text changed, and this thread helped.
---
I have created and maintained countless Drupal-powered sites and have made heavy modifications to modules on a site-by-site basis. I am an illustrator, a game developer, and a web developer. I also stream on Twitch in my spare time.
Another way using template.php
Replace custom_type with your content type machine-readable name and replace theme name with your theme (replace basic with your theme name).
tried this and the result
tried this and the result is:
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'fusion_starter_myform_node_form' was given in /var/www/vhosts/xxxxxxx/httpdocs/xx/includes/theme.inc on line 656.
Button position is moved further up the form, but the text doesn't change?
Drupal Web Designers Surrey South East England www.lightflows.co.uk
using javascript
Laff! For all you folks pounding your head on the Drupal module wall, here is a way that needs no template changes, no new modules.
1. Create a block
2. Put that block in the footer or somewhere below the form
3. Set the block to only show up on the particular URL where you want the button changed... for instance click "Show on only the listed pages." and then put in the box "node/*/edit" or whatever you want
4. set the block body to FULL HTML input mode
5. put this in the block body
<script language="javascript">document.getElementById("edit-submit").value="NEW BUTTON TEXT";</script>
Tested and works in IE6, IE7, IE8, Firefox, Chrome. Assuming it works in Opera and Safari, but I don't have them browsers installed at the moment.
simple solution
http://drupal.org/project/stringoverrides
Wow!. Smart way!!!!!!!!!!!
Wow!. Smart way!!!!!!!!!!!
Drupal Theme generator
On Safari if the form does
On Safari if the form does not validate the text change moves to the next button (in my case the Search button)
Can "edit-submit" be a path in someway? e.g. "node-form.edit-submit"
Any java-scripters??
The template.php seems the
The template.php seems the simpist method but the code gives me a white screen.
Thanks a lot mate, was
Thanks a lot mate, was looking for an elegant way to customize Save button text for quite a while, and yours is just perfect!
Change the text on Comment forms from 'Save' to 'Post'
Change the text on Comment forms from 'Save' to 'Post'
First, create the folder sites/all/modules/comments_save_button
In that folder create 2 files:
Create one file "comments_save_button.info" with this text
Create a second file "comments_save_button.module" with this text
Then go into your modules and enable your new module called "Comments Save Button"
How about for a node type
It doesn't work for me,,, and it gives me the below error
string(10) "user_login"
Does any one have any idea what does this mean?~ thank you.
in D7 the following statement works for me :
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Log in'));
jquery hack
This works well if you don't mind a dirty jquery hack
$('#forum-comments #edit-submit').val('Post');
Code for generic node type, with examples for all 3 buttons
First, create the folder sites/all/modules/change_default_button_values
In that folder create 2 files:
Create one file "change_default_button_values.info" with this text
Create a second file "change_default_button_values.module" with this text
Then go into your modules and enable your new module called "Change Default Button Values".
Thanks to Alan D. for the above comment with more detailed information on button names and properties, to moon.watcher for hints on more detailed button-setting code, and to Sepero whose detailed example code let me figure this out faster!
"wrapping text in t('text
"wrapping text in t('text here'); code is an important security & multi-lingual coding step."
For contributed modules, yes this is important for multi-lingual support. Security, no. It is just a wrapper for translation and other cool things like the string overrides. It does not sanitise the string.
For Drupal 6 be careful not to nuke the content type settings page at the same time (the above targets both).
Use:
Alan Davison
Perfect solution, Sepero!
Hi Sepero,
I followed your instructions exactly in my Drupal Commons 1.7 site (based on Drupal 6.x). It worked perfectly. I was able to produce the requested change with your solution immediately. Thanks for contributing!!
Kathy
These threads are a bit hard
These threads are a bit hard to follow sometimes with the number of posts and corrections made. I recently wrote about changing the 'save' button text and other form submit buttons in my blog which will hopefully help some of you that stumble here looking for answers.
Bug with my module in Drupal 7
I have created a new module for myself to change the comment "save" button to read "Save and continue". However the button has not changed. I am not sure why.
I took a look at the core module "comment.module" and found the "save" action located at line 2030. I created the following function to alter this text.
This did not work. I also tried other variation similar to the comments above but the text is not being changed. What am I missing ?
Thanks,
spineless
Better late than never?
@Spineless - you're likely missing the correct form_id of the comment form.
Typically it includes your entity and content type in the form id.
You can check form_id's by writing them out inside a form_alter, e.g.
See Node buttons edit Module
I tried this and worked great for D7 https://drupal.org/project/node_buttons_edit
This link: https://www.drupal
This link: https://www.drupal.org/node/1174284#comment-5102438 worked for me.