With drupal 6 you can use the theme_submit() function to change the value of submit buttons, including those on the node forms without issue. The same cannot be said for theme_submit() in drupal 5. I learned this the hard way at the Fearless City code sprint when I overwrote theme_submit() which resulted in it being impossible for users to add and edit nodes.
For a Drupal 6 website, the following code will replace the 'Save' button text with 'Create' when adding a node and with 'Commit Changes' when editing existing nodes. It is placed in the theme's template.php file.
function phptemplate_submit($element) {
if(arg(0) == 'node' && arg(1) == 'add') {
$element['#value'] == t('Save') ? $element['#value'] = t('Create') : '';
} elseif(arg(0) == 'node' && arg(2) == edit) {
$element['#value'] == t('Save') ? $element['#value'] = t('Commit Changes') : '';
}
return theme('button', $element);
}In this instance, the button text value is changed and the node form continues to work as expected.
For a Drupal 5 website, the code would need to be modified slightly; replacing ... == t('Save') ... with ... == t('Submit') ... as follows:
function phptemplate_submit($element) {
if(arg(0) == 'node' && arg(1) == 'add') {
$element['#value'] == t('Submit') ? $element['#value'] = t('Create') : '';
} elseif(arg(0) == 'node' && arg(2) == edit) {
$element['#value'] == t('Submit') ? $element['#value'] = t('Commit Changes') : '';
}
return theme('button', $element);
}The form is altered as one would expect; the text value of the button is changed. When the form is submitted, however, nothing happens. The node is not created or updated.
At present, I'm not really sure what's going on. I'm not too familiar with the inner workings of the form api and node module. I know that <a href="http://api.drupal.org/api/function/node_form_submit/5">node_form_submit()</a> is not getting called when a user tries to submit a node if the node form has been altered via theme_submit(). I also know that this only affects the action of node forms. If you apply the submit text value change to all forms using the following snippet:
function phptemplate_submit($element) {
$element['#value'] == t('Submit') ? $element['#value'] = t('>> Submit >>') : '';
return theme('button', $element);
}The node form still doesn't function, but all other forms (e.g. the user account edit form) function as the user would expect.
At the time of writing, I'm still trying to get to the bottom of why this happening in Drupal 5, and likely I will post a follow-up should I ever figure it out. But here are a couple of options if you're experiencing the same problem:
Add your comment