I am coding a Drupal Module wich limits the node creation to users who bought some products. e.g. A user bought a 5 photos + 5 videos pack, the module limits his number of photos & videos he can create to 5.

I got an issue with the admin form :

function product_node_limit_admin($form, &$form_state) {

    foreach ($products = product_node_limit_get_products() as $result) {

        $product = commerce_product_load($result->product_id);

        $form[$product->title] = array(
            '#type' => 'fieldset',
            '#title' => $product->title,
            '#collapsible' => TRUE,
            '#collapsed' => FALSE,
            '#tree' => TRUE

        $form[$product->title]['cumul'] = array(
            '#type' => 'checkbox',
            '#title' => t('Cumulative'),
            '#required' => FALSE,

        $value = variable_get($product->title, 1);

        foreach ($types = product_node_limit_types() as $type) {

            $form[$product->title][$type['type']] = array(
                '#type' => 'textfield',
                '#title' => $type['name'],
                '#size' => 10,
                '#maxlength' => 10,
                '#required' => FALSE,
                // '#attributes' =>array('placeholder' => ($value[$type['type']] != '') ? $value[$type['type']] : 0),
                '#element_validate' => array('element_validate_integer_positive'),
                '#default_value' => ($value[$type['type']] != '') ? $value[$type['type']] : 0,



    return system_settings_form($form);


The form

This gives me a form but when I submit it I got an error (the inputs are not recognized as integers even if I put integers in them) , and when I dump the $form_state after validation, the ['#values'] index has no values (and the ['#input'] index has the good values). So Drupal doesn't save the values to the variable table.

I dumped the $value and it was empty, and when I put 7 in the '#default_value' index, $value got 7. I think the issue is in the default_value index.

I checked on the stack and found a topic just like this but the answer didn't helped me at all .

How comes the ['#values'] stays empty ?

Here is the menu_hook I did

function product_node_limit_menu(){

    $items = array();

    $items['admin/commerce/config/product_node_limit'] = array(
        'title' => 'Product node limit',
        'description' => 'Exemple de configuration ',
        'page callback' => 'drupal_get_form',
        'page arguments' => array('product_node_limit_admin'),
        'access arguments' => array('administer site configuration'),
        'file' => 'product_node_limit.admin.inc',
        'type' => MENU_CALLBACK,

    return $items;

closed as off-topic by kiamlaluno Apr 8 '16 at 11:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced, was solved by a cache clear, or was a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." – kiamlaluno
If this question can be reworded to fit the rules in the help center, please edit the question.


OK the solution was so simple it makes me cry : 'DO NOT PUT SPACES IN THE $FORM ARRAY KEYS'.

It works like a charm since I replaced ' ' by '_' in the array keys. I feel so stupid ...


The value which u are accessing in default value, always set conditions to 0, so which Drupal considers not be a positive Integer.

What u can do is:

'#default_value' => (variable_get($type['type']) != '' )?variable_get($type['type']):0,

It will not give u error, and will show your values when it is saved.

Not the answer you're looking for? Browse other questions tagged or ask your own question.