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 973217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:14:47+00:00 2026-05-16T03:14:47+00:00

I don’t have experience in php. I’ve followed a few tutorials to modify my

  • 0

I don’t have experience in php. I’ve followed a few tutorials to modify my Drupal forms using the theme method in template.php.

For some reason the [#weight] property for a field does not adhere to its values. I’d like to move the Category field [cid] above Subject field [subject].

These are the lines of code I used:

$form['cid']['#weight'] = 0.003;
$form['subject']['#weight'] = 0.004;

When I print my array to view I see the values have changed, but when I render the form no changes are made. I have already cleared performance cache after every modification.

Here is a snippet of my printed array:

[subject] => Array
        (
            [#type] => textfield
            [#title] => Subject
            [#maxlength] => 255
            [#required] => 1
            [#post] => Array
                (
                )

            [#programmed] => 
            [#tree] => 
            [#parents] => Array
                (
                    [0] => subject
                )

            [#array_parents] => Array
                (
                    [0] => subject
                )

            [#weight] => 0.004
            [#processed] => 1
            [#description] => 
            [#attributes] => Array
                (
                )

            [#input] => 1
            [#size] => 60
            [#autocomplete_path] => 
            [#process] => Array
                (
                    [0] => form_expand_ahah
                )

            [#name] => subject
            [#id] => edit-subject
            [#value] => 
            [#defaults_loaded] => 1
            [#sorted] => 1
        )

    [cid] => Array
        (
            [#type] => select
            [#title] => Category
            [#default_value] => 1
            [#options] => Array
                (
                    [1] => General Enquiries
                    [2] => Support
                )

            [#required] => 1
            [#post] => Array
                (
                )

            [#programmed] => 
            [#tree] => 
            [#parents] => Array
                (
                    [0] => cid
                )

            [#array_parents] => Array
                (
                    [0] => cid
                )

            [#weight] => 0.003
            [#processed] => 1
            [#description] => 
            [#attributes] => Array
                (
                )

            [#input] => 1
            [#size] => 0
            [#multiple] => 
            [#process] => Array
                (
                    [0] => form_expand_ahah
                )

            [#name] => cid
            [#id] => edit-cid
            [#value] => 1
            [#defaults_loaded] => 1
            [#sorted] => 1
        )
  • 1 1 Answer
  • 2 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-16T03:14:48+00:00Added an answer on May 16, 2026 at 3:14 am

    You generally see that behavior on node forms when CCK is enabled. This is because CCK overrides weight for the default and CCK fields with its own ordering system configurable by going to Content management -> Content types -> [Content Type] -> Manage fields.

    Of course, if you disable CCK (probably not an option), your #weight values will be respected.

    One thing to note is that while Forms API allows decimals for #weight, it’s good practice to use integers.


    Edit

    If you want to work within the constraints CCK presents, in a custom module you’ll need to implement a #pre_render handler that will alter the weights of the form elements after CCK alters them:

    function mymodule_form_alter(&$form, &$form_state, $form_id) {
      $form['#pre_render'][] = 'mymodule_form_alter_weight';
    }
    
    function mymodule_form_alter_weight($elements) {
      $elements['cid']['#weight'] = 0.003;
      $elements['subject']['#weight'] = 0.004;
    
      return $elements;
    }
    

    The problem is, you will have no idea what weight values CCK has used for other form elements, so while you’ll have ordered cid before subject, both fields might show up in the middle of all the other fields on the page and not in their original position.

    CCK forces you into a corner when it comes to weight. The correct, Drupal/CCK way to handle form ordering is to respect the choices made by an administrator on Content management -> Content types -> [Content type] -> Manage fields.

    If you have a custom form element, you can tell CCK about it so it shows up in Manage fields by implementing hook_content_extra_fields(). Continuing with the code above:

    function mymodule_content_extra_fields() {
      $extras['mymodule'] = array( // Name of field
        'label' => t('Mymodule'),
        'description' => t('Mymodule field'),
        'weight' => 10, // The default weight, can be overriden on Manage Fields
      );
    
      return $extras;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't ask me how but I'm in a situation where I have DCPs published
Don't think that I'm mad, I understand how php works! That being said. I
Don't they both have to convert to machine code at some point to execute
Don't overthink this - there's a very commonly used term and I ... have
Don't know what's wrong here, when I run the application it says Specified method
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't know a whole lot about streams. Why does the first version work using
Don't think my virtualhost is working correctly. This is what I have inside of
Don't know why this is happening, but after submitting a form via JS (using
Don't ask why but I have the requirement to draw a border around certain

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.