#default_value not being displayed in form Here's a function that returns a form:

function myfunc($str)
{
    $form = array();
    $form['header text'] = array(
        '#markup' =&gt; '&lt;h2&gt;blah blah blah&lt;/h2&gt;',
    );
    $form['new_str_value'] = array(
         '#type' =&gt; 'textfield',
         '#title' =&gt; 'New String Value',
         '#size' =&gt; 60,
         '#maxlength' =&gt; 128,
         '#required' =&gt; TRUE,
         '#default_value' =&gt; $str,
    ); 

    return $form;
}


The textfield displays correctly with the right size and label, but it is not populated with an initial value. Any ideas? Should I be rendering or building the form in the function before returning it, or setting the value in $form_state ... or something?

Any help much appreciated!
Assuming Drupal 7...

The signature for form functions needs to follow a strict pattern; Drupal will pass along $form and $form_state as the first two args, and anything else as subsequent args.

So assuming $str should be the first custom arg to the form, the signature should look like this:

function myfunc($form, &amp;$form_state, $str) {