Hi

I am trying to create a form. One of fields should contains name like "info.field.label". Drupal can't post the variable for that field after I press the submit button.

            [info.field.label] => Array
                (
                    [#type] => textfield
                    [#title] => Field label info
                    [#required] => FALSE
                    [#default_value] => test value
                )

Is it bug?

Comments

marcvangend’s picture

That's not a bug, it's how PHP is designed. The dot is not allowed in variable names, see http://www.php.net/manual/en/language.variables.basics.php. You can use underscores: info_field_label. If you still need "info.field.label" as a string, add it as a value to your array, or do a str_replace('_', '.', $name) on the name when you need it.

dproger’s picture

How drupal works at all?

$test = array();
$test['test.array.here'] = 'Here is my test message';

in normal php work above statements will work fine!

marcvangend’s picture

I'm sorry, I wasn't completely correct. While dots are not allowed in variable names, they are of course in array keys, so $test['test.array.here'] = 'Here is my test message'; is valid php.
However, the Drupal theme system takes an array with variables and extracts the contents into separate variables with extract($variables, EXTR_SKIP) (see http://api.drupal.org/api/function/theme_render_template/6). While doing this, array keys that would result in invalid variable names, are skipped. That would explain disappearing values.