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

  • Home
  • SEARCH
  • 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 556193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:53:38+00:00 2026-05-13T11:53:38+00:00

I am working with a hook_form_alter on a CCK type (for you drupal-ers). I

  • 0

I am working with a hook_form_alter on a CCK type (for you drupal-ers). I have a field that is normally a select list in my node form. However, in this instance, I want to hide the select list, and populate its value in the form with an SQL query.

Everything was going nicely. I could see that my desired value was showing up in the HTML source, so I knew my query was executing properly. However, when I submit the form, it only inserts the first character of the value. A few of my tests were values of 566, 784, 1004 – the column values were 5,7,1, respectively.

At first I thought it had to be the DB column attributes, but when I removed my form_alter that makes the field hidden and select the value manually, the correct value is inserted?!?

   <?php
function addSR_form_service_request_node_form_alter(&$form, $form_state) {
       if (arg(0) == 'user' && is_numeric(arg(1))) {
        $account = arg(1);
        $club = 2589;
        $form['field_sr_account'] = array( '#type' => 'hidden',
        '#value' => $club
        );

           }
}


?>

Can anyone see why only the first character would be inserted??

Note: I have tried deleting and recreating the column, using #value & #default_value, and it is still submitting only the first character of the integer. Also, I eliminated the submit handler as a possible cause by removing it, which still resulted in only one character being submitted

More Updates – Still Searching!
Okay, some good questions. Allow me to answer them:

  1. The DB column type is integer(4)
  2. The HTML the hook produces is :

    input type=”hidden” name=”field_sr_account” id=”edit-field-sr-account” value=”2589″

Latest Update: I think the issue has been narrowed to the structure of the array. When I do var_dump on this field after the form alter has been processed, this is what I get..

[43] => Array
        (
            [#type] => hidden
            [#default_value] => 2589
            [#post] => Array
                (
                )

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

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

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

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

            [#name] => field_sr_account
            [#id] => edit-field-sr-account
            [#value] => 2589
            [#defaults_loaded] => 1
            [#sorted] => 1
        )

What is the structure of the field that I can set the form value to. It’s gotta be something like what abhaga is suggesting..

  • 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-13T11:53:39+00:00Added an answer on May 13, 2026 at 11:53 am

    Since the field you are trying to change was originally using a select widget, CCK will be looking for $form_state['values']['field_sr_account'][0]['value']. By setting the field to a #hidden type and setting #value, you will get its value in $form_state['values']['field_sr_account']. CCK will try to access the first element of that and end up with the first character of the value.

    Updated: The easiest way to achieve what you need would be to do something:

    function addSR_form_service_request_node_form_alter(&$form, $form_state) {
       if (arg(0) == 'user' && is_numeric(arg(1))) {
        $account = arg(1);
        $club = 2589;
        // Use this property to store the value to restore back
        $form['#field_sr_account'] = $club;
        $form['field_sr_account'] = array( '#type' => 'hidden','#value' => $club);
       }
    }
    
    /*in your submit handler, restore the value in the proper format*/
    $form_state['values']['field_sr_account'] = array('0' => array('value' => $form['#field_sr_account']));
    

    Old Answer

    One way of accomplishing what you are
    trying to do is to copy the whole
    $form['field_sr_account'] into
    $form['#field_sr_account'] and then
    provide the value through the SQL
    query in the right format in the
    submit handler itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I needed to create a custom select list for the user registration page that
I have a form that is added through the nodeapi displayed only on view
I am working on an application that installs a system wide keyboard hook. I
I am working on a c++ win32 program that involves a keyboard hook. The
Working with a SqlCommand in C# I've created a query that contains a IN
Working on a project at the moment and we have to implement soft deletion
Working on a project that parses a log of events, and then updates a
I would like to create a plugin that uses the contact form 7 hook,
A common occurrence I have with one particular project is that it requires the
I have a new app (Rails 2.3.8) that uses lots of money fields. I'm

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.