English 中文(简体)
drupal form textfield #default_value not working
原标题:

I am working on a custom module with multi-page form on drupal 6. I found that #default_value is not working when my #type => textfield . However, when #type => textarea , it displays correctly with the #default_value specified.

Basically, I wrote a FormFactory to return different form definition ($form) based on the post parameter received. Initially, it returns the display of directories list, user then selects from radio buttos until a specific directory contains a xml file, it will become edit form. The edit form will have text fields display the data (#default_value) inside the xml file, however the type textarea works here rather than textfield .

How can I make my #default_value work in this case?

Below is the non-working field definition:

$form[ pageset ][ newsTitle ] = array(
                                       #type  =>  textfield ,
                                       #title  =>  News Title ,
                                       #default_value  => "{$element->newsTitle}",
                                       #rows  => 1,
                                       #required  => TRUE,
                                      );

Then I changed it to textarea as shown below to make it work:

$form[ pageset ][ newsTitle ] = array(
                                       #type  =>  textarea ,
                                       #title  =>  News Title ,
                                       #default_value  => "{$element->newsTitle}",
                                       #rows  => 1,
                                       #required  => TRUE,
                                      );
问题回答

There should be no difference between a textfield and a textarea form element concerning the usage of the #default_value attribute, and both work for me as advertised. So if it does not work in your case, you should check for typos or other differences that might cause the faulty behavior.

Could you edit your question and add your form definition code?

What Drupal versions are you on? I m on 6.16 and I m having weird behaviour for defaults too. In my case, not working for textareas.


I m a non-english speaker and my default_value had non ascii characters. It s fixed now using translation.





相关问题
Drupal Multi-language: Simple strings not translated

I m adding additional languages to a Drupal site that I m building. Getting the translation of content working is fairly easy using the Internationalisation module. Yet, simple things such as date ...

Setting up a WYSIWYG editor for Drupal site users [closed]

Looking through the Drupal contrib modules, and after a few Google searches, it becomes evident that there are any number of choices and combos available to set up a WYSIWYG editor in Drupal. I m ...

Change size of user/password login box

I don t know how to change the size of the login username/password boxes on the drupal site that I m trying to build. I m stumbling through the theming, and don t know where to find the file that ...

How does Drupal provide an edit/review/publish model?

How does Drupal support a means to update and review a website before it is published? Does it only allow you to preview a page at a time before you publish it or is there a way to create a site ...

Term for rotating header

I m looking for terminology that describes this behavior: The header of a web-page contains a different image every time you visit it. Update: It is not an advertisement, but images related to the ...

Has anyone checked out Drupal 7? [closed]

Has anyone checked out a copy of Drupal 7 yet? What do people think? I m pretty excited about the PDO and all of the designers I work with a very excited about the new admin interface/structure. Do ...

热门标签