Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 1257

Use it for questions about the Form API. Don't use it for entity or entity field forms.

1 vote

how to link a select field options with the database records

Check out the Form API reference, especially the part about select lists: <?php $form['selected'] = array( '#type' => 'select', '#title' => t('Selected'), '#options' => array( …
Bart's user avatar
  • 6,944
18 votes
Accepted

How can I find the form ID of a form?

Try printing the form variables with PHP function print_r. function hook_form_alter(&$form, &$form_state, $form_id) { print_r($form); } When you visit the page the form is on, the variables (and …
Bart's user avatar
  • 6,944
1 vote
Accepted

Drupal autocomplete form, multiple values

Add a select list to your form. Add some #ajax to your textfield. Every time the textfield changes content, add the value (via #ajax) to your select list. Use the values of your select list in the sub …
Bart's user avatar
  • 6,944
3 votes

How to rename uploaded file using form API and Drupal managed_file field

Assuming you know about file status, file_save & file_usage_add. In your submit callback: $file = file_load($form_state['values']['image_fid']); $file->filename = 'somefilename'; $file->status = FIL …
Bart's user avatar
  • 6,944
49 votes
Accepted

How do I set allowed extensions for a managed_file form field?

$form['picture']['file'] = array( '#type' => 'managed_file', '#title' => t('picture'), '#description' => t('Allowed extensions: gif png jpg jpeg'), '#default_value' => (isset($foo->picture->fi …
Bart's user avatar
  • 6,944
0 votes
1 answer
4k views

Error using form API on AJAX submit

I am writing a form using the Drupal 7 form API. On submitting the form (via AJAX), the following error is displayed: An AJAX HTTP error occurred. HTTP Result Code: 500 Debugging information f …
Bart's user avatar
  • 6,944
40 votes
Accepted

Managed file: the file used in the field may not be referenced

The solution is to add a call to file_usage_add after the file is saved. This call adds a reference to the file in the database. The file_managed_file_validate function will spot the reference and won …
Bart's user avatar
  • 6,944
5 votes
Accepted

Rendering theme_item_list items

Something like this: foreach ($images as $image) { // New array for readability $options = array( 'path' => $image->url, 'alt' => $image->alt, ); // Push the image tag onto the item …
Bart's user avatar
  • 6,944
1 vote
3 answers
3k views

Form API AJAX refreshes page

I need to add some AJAX functionality to a node form. Using hook_form_alter I'm overriding form elements. In this particular case I need to add a callback on the 'language' element provided by the tra …
Bart's user avatar
  • 6,944
41 votes
1 answer
19k views

Managed file: the file used in the field may not be referenced

I am having some issues with the managed_file type. Whenever I try to edit and save a form that has a managed_file element in it an error occurs: The file used in the Picture field may not be referen …
Bart's user avatar
  • 6,944
5 votes
4 answers
7k views

Form element #default_value and AJAX

I can't get a form to display a (default?) value after an AJAX call. I am using the following code: function foo_form ($form, &$form_state, $foo) { $form['#prefix'] = '<div id="foo-form-wrapper">' …
Bart's user avatar
  • 6,944
10 votes
3 answers
8k views

hook_form_alter execution order

Is there a way to change the order of execution of hook_form_alter in Drupal 7 without changing a module's weight or hacking Drupal Core? I am trying to alter the element added in translation_form_no …
Bart's user avatar
  • 6,944
4 votes

specify $form elements to be excluded from display?

If you're using a template file you can hide stuff using hide(). If you want to hide a form element in hook_form_alter, unset() might be your best option. If it's just to store a value you could use …
Bart's user avatar
  • 6,944
2 votes
1 answer
597 views

WYSIWYG error when using managed_file and AJAX

I have a form that has both a managed_file element and a text_format element. Both are encapsulated in a wrapper div (using #prefix and #suffix). On submit, an AJAX callback is executed and both eleme …
Bart's user avatar
  • 6,944