One of the issues that have come up from one of our users who is editing content, is that they have to often scroll all the way to the bottom of a page to click the "Save" button. Sometimes because they just change the title, or a piece of text in the body ... they miss the Save button and close the screen/browse elsewhere.

It's been suggested that it would be useful to also have the saving/preview buttons at the top of the page, as well as the bottom. How would I go about doing this? (Or even just adding in an anchor link to go to the bottom of the page?)

I've searched around for examples, but it seems no-one else has done anything similar. Any help would be really appreciated!
Thanks!

Comments

ainigma32’s picture

This will add a link above the form pointing to the bottom of the form:

function phptemplate_node_form($form) {
  $top = '<a href="#bottom_form">'. t('Goto bottom') .'</a>';
  $bottom = '<a name="bottom_form">&nbsp;</a>';
  return $top . drupal_render($form) . $bottom;
}

Add the code to the template.php file of your theme.

HTH

Arie

fgasking’s picture

That is brilliant Arie! ... thanks very much, works a treat and opened up the solution with the buttons for me also!

One issue I had was that the rendering of the form put the submit buttons within the middle of the fields (Seems some custom fields from modules get put underneath and do some weighting changes before rendering).

However, I got round the issue by modifying the weight of the 'buttons' form element before rendering. It also enabled me to replicate the form element with a lower weighting, so now I have buttons at the top and bottom of the form.

So for example (Weighting is a bit extreme I know at the moment):

$form['buttons']['#weight'] = "-1000";
$form['buttons2'] = $form['buttons'];
$form['buttons2']['#weight'] = "1000";
philpro’s picture

Could you please share your whole code solution for placing the buttons on the page?

artatac’s picture

In drupal 6 I added the following to \modules\node\node.pages.inc just above $form['body'] = array(

  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#access' => !variable_get('node_preview', 0) || (!form_get_errors() && isset($form_state['node_preview'])),
    '#value' => t('Save'),
    '#weight' => 5,
    '#submit' => array('node_form_submit'),
  );

not happy about hacking core but for simple pages it is a pain to have to scroll to the bottom every time for no good reason.

Let us hope someone tells us both off and that a more elegant solution is found! (remember to backup the file first)

ore’s picture

to alter a form without touching core just use hook form alter.

eg

from within any MODULE you have made

function MODULENAME_form_alter(&$form, &$form_state, $form_id) {
	if($form_id == 'formname_node_form' ){
	$form['buttons']['#weight'] = 35;   //move to below the publishing options.
	}
}

where modulename is the name of the module this code will go in eg myforms.module and formname is the name of the form you want to alter. you can find this by using var_dump($form_id); before the if statement and refresh the form page you are on and it will print the id out at the top of the page.

hope this helps someone.

dman’s picture

I've been meaning to roll up a UI patch that would grab the node edit buttons from the bottom of the form and anchor them to the bottom of the window using position:fixed !
This (idea) was suggested by a new user and it just seemd to make so much sense - when the node form was so many pages deep. I know how to use the [END] key, but having the button always there would be even better.
I was going to have a look at how that table header scrolling magic works. ... haven't got around to it yet.