Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6853795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:33:15+00:00 2026-05-27T01:33:15+00:00

I have a form in a custom Drupal 6 module built with the Form

  • 0

I have a form in a custom Drupal 6 module built with the Form API, it has 1 or more image_button elements in a list followed by the Save and Cancel buttons.

Everything is working fine when clicking the image and standard buttons, they call the submit functions they should, but if I hit the [ENTER] key within any of the text fields in the form the first button in the form is submitted, which unfortunately in this case is an image_button in the list rather than the Save button.

This is a standard problem with web forms, you generally have to hack in a hidden (by style and/or size) button early in the form definition to ensure the default submit path is called (in this case that’s what the Save button will call) rather than the submit path for the buttons that are before the button you want to be the default.

Is there some Drupal 6 magic that enables setting a default button regardless of where it is in the form definition that I’ve failed to find in the docs, or should I create a phantom submit button that is styled to not be visible?

Thanks in advance for any answers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:33:16+00:00Added an answer on May 27, 2026 at 1:33 am

    The answer seams to be no, there is no built in Drupal method of getting around the problem of the first button in a form being the default when pressing [ENTER].

    Here is what I had to do.

    I created an extra submit button at the top of my form:

    // A submit button that needs to be hidden, it'll be the default rather than one from the list.
    $form['hidden-submit'] = array(
      '#type' => 'submit',
      '#value' => 'Save',
      '#attributes' => array('class' => 'hidden-default-submit'),
    );
    

    In the CSS included for the page I added the following belts and braces CSS to hide the extra submit button in as many web browsers as I could test:

    .hidden-default-submit {
      position: absolute;
      left: -2000;
      top: -2000;
      width: 0;
      height: 0;
      border: 0;
      margin: 0;
      padding: 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom form implemented in a custom module in drupal 6. The
I have a list within Sharepoint, using a custom new form I have added
I have a custom Drupal module displaying some data in a table. Each row
i have created a custom form in my custom drupal6 module and the form
I have a custom form... I'd like to auto save the author (authenticated user)
I have a form and it has tones of other controls(buttons, custom controls, labels,
I'm working on a custom module in Drupal with a multi-page form approach, and
In a custom module nade_reg I have changed the registration form to include two
I have custom Question objects which I render into html form elements. I want
I am currently working on a custom form module in Drupal 6. In this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.