form-api

Drupal 6: Only inserting first character of value to MySQL

我的未来我决定 提交于 2020-01-06 03:37:06
问题 I am working with a hook_form_alter on a CCK type (for you drupal-ers). I have a field that is normally a select list in my node form. However, in this instance, I want to hide the select list, and populate its value in the form with an SQL query. Everything was going nicely. I could see that my desired value was showing up in the HTML source, so I knew my query was executing properly. However, when I submit the form, it only inserts the first character of the value. A few of my tests were

'add another item' in non-CCK Drupal forms

亡梦爱人 提交于 2019-12-21 04:58:08
问题 CCK for Drupal has the handy feature of allowing a single CCK field to accept multiple values via a "add another item" button that results in an array of data in the node. I'm wondering if there's any easy way of adapting this for a non-CCK form that I'd be calling by drupal_get_form . I'd rather not have to re-invent the wheel with multi-step form techniques. Anyone done this? 回答1: It would be nice if they had included a more reduced example, but this Introduction to AHAH in Drupal, along

Drupal 7 retain file upload

自作多情 提交于 2019-12-09 23:58:11
问题 I have a file upload form how can I retain this file when there are other validation errors so that the user doesn't have to upload the file again? I tried this in my validation function but it doesn't work: function mymodule_someform_validate($form, &$form_state) { $form_state["values"]["some_field"] = some_value; } the $form_state["values"] variable is not available in my form definition function - mymodule_someform($form, &$form_state) Any ideas? 回答1: Just use the managed_file type, it'll

Drupal 7: Best Practice for a Dynamic Select List in Drupal 7

十年热恋 提交于 2019-12-03 05:21:33
问题 What is the best practice for a dynamic select list in Drupal 7? Create a Field with dummy options via the UI and overriding the options with hook_form_FORM_ID_alter or Creating a dynamic select list from scratch via a custom module with the hook_form or different approach? Thanks 回答1: You could use Form API's #ajax (it used to be called #ahah in Drupal6) to do that. Here is an example for Drupal 7 (based on Examples for Developers) that shows two dropdowns where the first dropdown modifies

Drupal 7: Best Practice for a Dynamic Select List in Drupal 7

爱⌒轻易说出口 提交于 2019-12-02 17:44:42
What is the best practice for a dynamic select list in Drupal 7? Create a Field with dummy options via the UI and overriding the options with hook_form_FORM_ID_alter or Creating a dynamic select list from scratch via a custom module with the hook_form or different approach? Thanks You could use Form API's #ajax (it used to be called #ahah in Drupal6) to do that. Here is an example for Drupal 7 (based on Examples for Developers ) that shows two dropdowns where the first dropdown modifies the list of options of the second dropdown: Source of file mymodule.module : <?php /** * Implementation of

How to disable a field or make it readonly in Drupal 7

ε祈祈猫儿з 提交于 2019-11-30 20:45:22
I am trying to disable couple of fields and make them readonly via hook_page_alter(). I was able to do check if user is viewing the page edit section (the form edit) $page['content']['system_main']['#node_edit_form'] == TRUE) then when I tried to disable couple of fields, I found that select list can be disabled by this code: $page['content']['system_main']['field_my_field_name_a_select_list']['und']['#attributes']['disabled'] = TRUE; but if I use the following code it doesn't work: $page['content']['system_main']['field_my_field_name_a_select_list']['und']['#disabled'] = TRUE; I also found

How to disable a field or make it readonly in Drupal 7

女生的网名这么多〃 提交于 2019-11-30 05:10:11
问题 I am trying to disable couple of fields and make them readonly via hook_page_alter(). I was able to do check if user is viewing the page edit section (the form edit) $page['content']['system_main']['#node_edit_form'] == TRUE) then when I tried to disable couple of fields, I found that select list can be disabled by this code: $page['content']['system_main']['field_my_field_name_a_select_list']['und']['#attributes']['disabled'] = TRUE; but if I use the following code it doesn't work: $page[