[development] Weird behavior on #default_value

John VanDyk jvandyk at iastate.edu
Thu Jan 24 15:30:49 UTC 2008


If #value is set, #default_value will be ineffective. From form.inc:

       if (!isset($form['#value'])) {
         $function = $form['#type'] . '_value';
         if (function_exists($function)) {
           $function($form);
         }
         else {
           $form['#value'] = 
isset($form['#default_value']) ? 
$form['#default_value'] : '';
         }
       }

Because the form is built multiple times, this can be confusing.

>I already try with print_r !
>
>it shows the content "array(['name'] => 'name 
>test')" in #description and #value, but never on 
>#default_value
>
>The name field is varchar(50), with 'name test'.  Just it.
>
>Yesterday a PHP expert was here, he take a look 
>at this, we try a lot of possibilities, no clue 
>whatsoever
>
>It cant be explained :)
>
>
>Jakob Petsovits escreveu:
>
>>On Thursday, 24. January 2008, Feijó wrote:
>>
>>
>>>  If I try
>>>      '#default_value' => 'test ' . $row['name'],
>>>
>>>  only test apears!
>>>    
>>>
>>
>>Imho, that behaviour suggests that something is wrong with $row['name'] and
>>less with Form API itself. (Because string concatenation fails even before
>>the Form API gets the value passed over.)
>>
>>Not sure, but maybe print_r($row) and/or gettype($row['name']) reveals some
>>useful information...
>>



More information about the development mailing list