Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
41 votes
1 answer
6k views

Why is hook_form_alter() so messy?

Here's an example I just ran into. I'm trying to put some HTML in the label of my field. $form['field_feedback']['und']['#title'] <- has the title $form['field_feedback']['und'][0]['#title'] <- ...
Joren's user avatar
  • 2,440
30 votes
5 answers
59k views

Dynamic select list in the form (dependent dropdown)

I'm using Drupal seven. I want to make the options in a select list be dependent on the value chosen in another select list in a form. I'm sure this has been asked many times before, but I am having ...
Ben's user avatar
  • 1,030
35 votes
2 answers
63k views

Custom validation for a form?

I need to add custom validation to a form, lets says add article form. I was expecting something like hook_FORM_ID_validate() to handle this, but cannot find anything relavant in the API ...
gilzero's user avatar
  • 6,037
7 votes
3 answers
17k views

Resolve the error "An illegal choice has been detected..."

I have written code like below and all works fine, but while submitting the form I get the error below. I am trying to filter the second dropdown based on the first drop down selection. An illegal ...
Hacker's user avatar
  • 3,024
21 votes
5 answers
29k views

Show forms in a modal window [closed]

I have a form and I am using Drupal 7. I need to show this form in a popup when a user clicks a link. The user should then be able to complete the form whilst in the pop up window. I can use anything ...
Hacker's user avatar
  • 3,024
41 votes
3 answers
61k views

Adding CSS and JS to form with attachments

I need to add some external and local CSS and JavaScript files to a form, but I can't seem to find the right way to do this. Do I simply add the paths and URLs for the JS and CSS files? I assume $...
vintorg's user avatar
  • 1,993
15 votes
2 answers
21k views

Form within a block

I'm using drupal_get_form('event_signup_form') to embed my custom form inside a block. The form is being rendered as intended, but submitting the form triggers nothing. The form function itself is ...
kristian nissen's user avatar
8 votes
3 answers
10k views

Can I use ajax to target multiple form elements from one input?

I'm trying to use ajax to update two different parts of a drupal form from just one form input blur. I have the standard ajax stuff on my input: $my_form['my_input']['#ajax'] = array( 'callback' =&...
Rick's user avatar
  • 471
3 votes
2 answers
8k views

Date popup form field doesn't show the default value correctly

I am creating a custom form with "date_popup" form fields. The only issue I have is that the default_value for the date popup form field shows only the first digit of the year, not the whole date. ...
swindler's user avatar
  • 141
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 ...
Bart's user avatar
  • 6,944
9 votes
2 answers
19k views

How can I display a change password form on its own?

I have a need to place a user's password reset form in areas outside the context of the user edit page. This Change Password module looked promising; however, it is only available for drupal 6 and ...
SMTF's user avatar
  • 946
7 votes
2 answers
4k views

How to implement a multi step approval with webforms/entityforms based on form components?

Is it possible to invoke multi-step submission workflow using either Webform or Entityform? Here is the scenario of workflows: An employee submits the form Superviser gets notification,...
JT-Drupal's user avatar
  • 115
7 votes
3 answers
21k views

How do you theme a content type's create/edit form?

Like it says -- I've got a D7 content type whose editing form needs to be themed. I did this all the time in D6 by registering theme functions in template.php and writing the associated theming ...
Jim Miller's user avatar
  • 1,948
20 votes
3 answers
19k views

Form Redirect not working if 'destination' is in URL

In one of my forms, I'm trying to set a $form_state['redirect'] so the form will go to that destination after the user clicks one of the action buttons. If I inspect $form_state['redirect'] both ...
geerlingguy's user avatar
  • 5,483
20 votes
3 answers
17k views

specify $form elements to be excluded from display?

I want to hide certain elements in form using form_alter or a template file. I have read somewhere that in Drupal 7 , we can specify $form elements so it will not display in form, but I can't remember!...
Serjas's user avatar
  • 1,357
3 votes
1 answer
13k views

How to theme webform elements (radio buttons etc.)?

I would like to know how to theme Drupal 7 Webform elements? I want to change the HTML structure of every element, not just wrap form with div or something like that. And I want to leave theme's ...
gregab's user avatar
  • 507
11 votes
2 answers
15k views

Webform - Submit values from Drupal 7 from to external url

I am a self-proclaimed newbie to creating forms in Drupal. I have a form hosted on a Drupal 7 website (using the webform module) and need to submit the form values to an external url. I've been ...
ForTheWin's user avatar
  • 235
10 votes
4 answers
21k views

How to make form buttons call only javascript?

I'm experimenting with JavaScript and Drupal forms. Currently I'm trying to make a button in the administration form of a module that will use JavaScript to append options to a select list. The ...
Sathariel's user avatar
  • 679
9 votes
1 answer
6k views

What is the maximum number of elements allowed in a form?

I have googled and binged and yahooed this question but can't seem to find an answer. I was working on a form that included over 800 fields but the form's submit function would never execute. After I ...
Robbert's user avatar
  • 563
5 votes
2 answers
7k views

Theme Drupal Form API checkboxes as a grid

I have a custom form that displays a form element of about 2 dozen checkboxes. I would like to output them 3 per row, in a table if possible. How can I go about doing that? $form['preference'] = ...
Kevin's user avatar
  • 28k
4 votes
6 answers
8k views

How to hide default "N/A" option for checkboxes?

I have a "gender" (checkbox) option that I want to show on the user profile page (but not on the registration page). The options are "Male" (default) and "Female". Since I don't make the field ...
uwe's user avatar
  • 12k
3 votes
2 answers
6k views

How to trigger Ajax forms machinery

I'm working on ajaxifying a form which uses Hierarchical Select widget. I need to update a text field based on the value of HS and a couple of other fields. I want to use Drupal forms Ajax API. I ...
Dmitry Vyal's user avatar
2 votes
2 answers
252 views

Custom Login form question

In my website have two types people login one is designer another is reader, i want people come to login my website by role. Mean designer go to design login form to login. Reader go to reader login ...
zeno's user avatar
  • 21
11 votes
4 answers
10k views

Print registration and login forms on same page

How do I print the register and login forms on the same page? I think I am really looking just for the form IDs, but if you've got the right render function handy it would be very appreciated.
emc's user avatar
  • 863
9 votes
2 answers
25k views

How do I use form_set_error() the right way?

In my Drupal 7 module, I have a form and its validation handlers. I call my form from a field.tpl.php with print render(drupal_get_form('my_form')); it works as expected. The problem is in case of ...
druvik's user avatar
  • 472
8 votes
1 answer
14k views

Changing the registration form

I would like to revise the default new user registration form in Drupal 7. Rather than to requst "username", I want to request "full name" with helper instructions to enter the text "username is your ...
JM Foster's user avatar
8 votes
3 answers
11k views

Disable all form elements when doing AJAX

I have a form where every user input field is AJAX enabled, and I'd like to disable all of the form elements when one of them is changed - is it possible?
Daniel's user avatar
  • 1,245
6 votes
2 answers
6k views

How to extend or "hook" Drupal Form AJAX?

I'm working with standard admin form, which has 'add_more' button for one of fields. My task is to move some fields to jQuery UI Dialog just for usability. When dialog was closed I manually append it'...
kalabro's user avatar
  • 7,949
5 votes
4 answers
2k views

I use jQuery to alter the exposed form select options. Got error: "An illegal choice has been detected." How to bypass validation?

I have a view that has three expose filters (Manufacturer, Type, Model), three options list (term reference to Printer vocabulary) . Vocabulary: Printer (3 levels) -- HP ---- xxx ---...
gilzero's user avatar
  • 6,037
4 votes
3 answers
5k views

How to add a confirm dialog to node add and edit forms?

Note: This has an accepted bounty, but no accepted answer because I still want to know how to add a node save confirm dialog using drupal code, not javascript. If you can write up a good answer on ...
UltraBob's user avatar
  • 1,339
4 votes
3 answers
586 views

Date field in FormAPI, remove Day field?

Using a 'date' field in the FormAPI, is there something I can set to hide the day field from showing?
Kevin's user avatar
  • 28k
3 votes
1 answer
3k views

Attach or embed node add form to a view

I want to attach or embed a node form to a view so that when a user submits the form, the view below the form will be updated in realtime via ajax. The form will be shown above the view. My views ...
Umair's user avatar
  • 441
3 votes
3 answers
7k views

Programmatically adding fields to node submission form

I need to add fields to a node creation/editing form programmatically. More specifically, I need to take already-generated form elements from another form and insert them into the node submission form....
beth's user avatar
  • 9,087
1 vote
4 answers
5k views

download file on form submission

I have created a form which has only a submit button. In the submit function I am generating csv file and saving it to the files folder using fputcsv function. But Now I need extra functionality of ...
Ahmad's user avatar
  • 2,845
1 vote
1 answer
2k views

How do I modify the attributes of <label>?

I need to be able to change attributes (like class, data-toggle, data-direction) of the label itself, at a PHP level, in a way that will support conditions in form definition function. The solution ...
Mołot's user avatar
  • 21.9k
1 vote
1 answer
4k views

EntityMalformedException: Missing bundle property on entity of type node in modal

I want to open create content type in modal, according to modal form and modal api example, I implement it, I test the problem is here when I test it by contact form ctools_include('modal'); ...
Yuseferi's user avatar
  • 22.2k
1 vote
1 answer
2k views

Change the disabled status of a form element via Ajax

I have a form built with the Form API. I have a field which is, at first, disabled. I want to change the status of that field to enabled when the user selects another contiguous field. I have a ...
Cesar's user avatar
  • 942
0 votes
4 answers
2k views

I get image field upload errors with a custom node_add() form

I've exposed a node_add form and styled it for certain roles to use. The form is being displayed in panels, through an 'article' node type using the PHP text filter. Users can create new nodes with no ...
emc's user avatar
  • 863
0 votes
1 answer
2k views

Remove tabledrag statuses on Ajax submit and display status message after Ajax submit

I've added drupal_add_tabledrag() on one of my custom forms, it enables the users to drag to reorder the elements' weights, which then gets submitted via ajax to a callback function that saves the ...
Beebee's user avatar
  • 6,856
20 votes
3 answers
31k views

Passing arguments to drupal_get_form()

How can I pass arguments to drupal_get_form() in Drupal 7? function new_menu_callback() { $vars = some_example_function(); // returns: array(1 => 'one', 2 => 'two'); $output = $vars[2]; $...
Citricguy's user avatar
  • 7,934
19 votes
3 answers
16k views

Embed a "node add" form in a page

I'm looking for a way to embed a "node add" form on a landing page. I was using Form Block, but it appears to bring many error because I was using a development snapshot version.
ousneo's user avatar
  • 325
14 votes
6 answers
64k views

How to validate and submit a form using AJAX?

I've created a webform using the Form API. I'm using the #AJAX field option to add AJAX validation to each field. Is it possible to validate and submit the form using AJAX without reloading the page. ...
Camsoft's user avatar
  • 3,139
13 votes
3 answers
21k views

How to disable the submit button after clicking?

Drupal doesn't seem to prevent multiple form submits, even on node pages. This QA suggests fixing it on the server side. How could I disable the submit button after clicking? Any other solutions?
uwe's user avatar
  • 12k
11 votes
1 answer
7k views

Why is my form themed as table not posting data correctly, or displaying correctly?

I have created a form in the admin. $form['things'] = array( '#prefix' => '<div id="things">', '#suffix' => '</div>', '#tree' => TRUE, '#theme' => 'table', '#header' ...
dm03514's user avatar
  • 417
10 votes
2 answers
42k views

Programmatically set the default value for a field

In Drupal 6, we could use PHP to set default values, but the same code cannot be used with Drupal 7. I am trying to do this through hook_form_alter(), but the code doesn't work. function ...
giorgio79's user avatar
  • 4,651
10 votes
3 answers
21k views

Image Upload in a Custom Module

I'm writing a custom module, and I need it to upload an image. I'm having trouble finding good documentation on this, but I think I'm close. What am I missing? $file returns false in the form ...
Tim's user avatar
  • 203
9 votes
3 answers
10k views

How do I create a progress bar?

I need to implement a progress bar using Drupal 7. This is the code I am actually using. $form[$name][$name.'_enc'] = array( '#type' => 'submit', '#value' => t($name.' Enable'), // '#...
amr's user avatar
  • 91
9 votes
1 answer
3k views

What is the difference between hide() function and unset()?

What is the difference between hide() and unset()? I want to hide some elements, I found hide() and unset(), but I don't know which one I should use.
Brian's user avatar
  • 157
8 votes
5 answers
11k views

How do you alter a form error?

How do you alter or remove a form error produced by Drupal or another module on node insert/save, for a particular content type. I'm looking for a method which I can use in a module. I've tried ...
Timofey Drozhzhin's user avatar
6 votes
1 answer
1k views

Unlimited value field in custom form, with remove button

I'm working on creating an unlimited value field in a custom form, and getting hung up on the remove button. I've been able to create a form that will pull the saved values for the fieldset, then ...
nkanderson's user avatar

1
2 3 4 5 6