Questions tagged [forms]

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

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

User registration form validate and submit hooks not called

I try to add custom validation or submit function to the user registration form, but nothing works. Here is the code in /sites/all/themes/mytheme/template.php: function ...
6
votes
2answers
3k views

returning #disabled in ajax callback

This is taken from the examples module(http://drupal.org/project/examples). More specifically in the 'Generate textfields' ajax section. The form attempts to demonstrate an ajax call by presenting 2 ...
6
votes
2answers
2k views

Adding a class to select options from Views Exposed Filters

Currently I have a views exposed filter for a "City" field. Typical output looks like: <option value="Liverpool">Liverpool</option> I would love to be able to add a class to this such as:...
6
votes
1answer
4k views

form_state->setRedirect(to_a_new_node_page) from the submitForm function, route “does not exist” issue

I created a custom module, It generate a custom Form in a page. When I submit my form, I create a new node. So, I am redirect to the form page but I would like be redirect to the new node page. I add ...
6
votes
3answers
7k views

How to add extra arguments/parameters to ajax callback function?

I am using drupal 7. I need to add extra arguments to my ajax callback function. I have five fieldsets in my form, and in all of them same there are same elements, just their IDs are different. For ...
6
votes
2answers
3k views

How to get Form API #states selected value onchange?

When I'm using #states to set the visibility of a form field I'm checking an input element for its value. Is there then any way to grab the selected value the moment it's selected? In the working ...
6
votes
2answers
4k views

hook_form_alter() exposed filter form item #weight

I'm trying to insert a form element with hook_form_alter(), and then rearrange the form elements so that the new form item appears at a particular point amongst the existing exposed filters. I've ...
6
votes
3answers
6k views

Field Validation and Highlighting

How can I get custom Form API validation to highlight a field the same way the failed #required validation does? (See attached graphic) Note Graphic: 1) (Green Line) Company Name is empty. '#...
6
votes
2answers
4k views

When should the “container” form element be used?

The System module defines the container form element, but that form element is not documented in the Form API Reference. When should that form element be used? What is its purpose?
6
votes
1answer
520 views

How to show a string once you submit a form in a page reloading the page?

I need to create a page with a form and once you enter some values in the form and send it make some calculations and show a string under the form. Something like this image: I know how to create a ...
6
votes
6answers
2k views

Is there an equivalent of view modes for form editing?

I have a content type with a lot of fields. End users need to create content of this type, so I want to provide them with a simplified form so that they can create a content item and edit it without ...
6
votes
2answers
103 views

Is there a standard Drupal way to link to 3rd party configuration forms?

I am writing a custom module. On my module's configuration form I would like to provide links to relevant modules' configuration forms; e.g. the cron configuration form. Is there a standard Drupal ...
6
votes
3answers
7k views

How to add a custom Save & <do some action> button to Node Add/Edit form?

I added the following code in hook_form_alter() and I get my button on the Add/Edit node form: $form['actions']['save_add_lesson'] = array( '#type' => 'submit', '#value' => 'Save & Add ...
6
votes
1answer
2k views

How to add separator option in Form API 'select' element?

Is there a way with the Form API to specify that one or more #options in a 'select' element should be disabled? I would like to insert a separator in my dropdown options that is not a selectable value....
6
votes
2answers
6k views

How to load modal form on page load using ctools?

I have an issue to show modal form on page load. This form will have 3 steps to submit. I've found CTools will suit the best. I'm newbie in drupal, that's why I've looked all tutorials ctools. Every ...
6
votes
3answers
2k views

Adding title attribute to #type password_confirm

Is it possible to add a title attribute through a form_alter to element #type 'password_confirm'? For example, I have a form with the following fields: email password password confirm To apply a ...
6
votes
2answers
5k views

How do I programatically submit a webform via drupal_form_submit?

Drupal 7, Webform 3 I want to programmatically submit a webform via drupal_form_submit. However, I'm having difficulty finding a $form_state structure that works. I've submitted my webform via the ui ...
6
votes
1answer
1k views

How do I append HTML after a form title?

This is the output I want: <label>Name</label><span>!</span> The only way I can think of is to concatenate my HTML to the form title value '#title' => t('Name') . '<...
6
votes
3answers
3k views

How can I change the order of vertical tabs?

More specifically, I am using Location in Drupal 7 to allow people to add location to nodes, but I want it to appear at the top of the vertical tabs fieldgroup.
6
votes
2answers
2k views

How should I handle container form elements?

I have added some custom fields to the register user form and I'm discovered that they are sent back, packaged in a form element of type "container". My code needs to handle all kind of different ...
6
votes
1answer
935 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 ...
6
votes
5answers
4k views

Content Type vs Webform vs Form API vs Custom Form vs? [closed]

I'm currently working on a new Drupal 7 site, which will be used as a data collection and reporting site. After much research / trial and error / etc, I've decided to bring this question to this forum,...
6
votes
2answers
13k views

Add fields to form dynamically with ajax and retrieve values

I am trying to add a combination of text field and a select box to a form dynamically using Drupal 7 Ajax, when i click on a button. But i have 2 issues here: I am not able to add more than 1 set of ...
6
votes
1answer
1k views

How do I add a menu subtitle to field sets displayed as vertical tabs?

I have formatted my field sets in a form builder function to display as vertical tabs. Here's a snippet of my code. It works fine: $form['vertical_tabs'] = array( '#type' => 'vertical_tabs', );...
6
votes
2answers
599 views

drupal_add_js and drupal_flush_all_caches

I was trying to call drupal_add_js in the callback of a button. It seems, even with after_build, that this can be done successfully only you are working without cached data. So, before i start the ...
6
votes
1answer
2k views

How do I validate form elements in a modal without closing?

I'm using Drupal 8 and I have defined a custom entity type 'my_entity_type', with form handlers defined in the @ContentEntityType annotation: * @ContentEntityType( ... * handlers = { * "...
6
votes
2answers
2k views

User Login Form Error Message Problem

I'm adding the user login form to the homepage of my site and through printing it out in my page.tpl.php, the validation is getting lost a bit. The first time I enter in an incorrect username or ...
6
votes
2answers
4k views

Drupal load form with ajax callback in Bootstrap modal

I need to load a form into a 'bootstrap modal dialog' which will submit data via ajax callback to callback function. The form display properly when the modal dialog is launched: <a data-toggle='...
5
votes
7answers
8k views

How to place Contact form in block?

I have to embed a contact form inside of a block, and I'm trying to use the entity.form_builder service, But I'm not sure which entity I should give it, I found Message and ContactForm entity, so what ...
5
votes
4answers
10k views

How do I set the default value of this form element?

I have a requirement of developing a custom contact form in drupal 8. I am able add all the fields but coming to date time field unable to set the default value to current date. This is my date field ...
5
votes
2answers
9k views

Removing input formatting options and description from comment form

How do I remove the input formatting options and descriptions from the comment form? I'm not interested in a CSS and/or jquery based solution, nor am I interested in using the Better Formats module, ...
5
votes
3answers
4k views

Is there a way to disallow spaces in the user name registration form in drupal 7?

I hate spaces in usernames, a user can easily add two or more spaces without realizing it. I need to have more control over the username format than Drupal allows by default.
5
votes
2answers
7k views

form_alter: Inline entity Form

I am using IEF and all is well...until I try ad implement hook_form_alter() and when I access the form via IEF UI (as opposed to directly modifying the entity) none of the changes I make appear to ...
5
votes
1answer
869 views

#states not working properly in IE 9

I am using #states form API to do the show hide animation of one element based on the values of another form element.like follows, $price['#states'] = array( 'visible' => array( ':...
5
votes
4answers
7k views

Creating node forms

Does anyone know how to create a node form for specific Content Types? Instead of clicking Content > Add Content > Content Type they can just, I don't know, go to the sidebar and fill out the info ...
5
votes
3answers
6k views

How do I prevent a form from being cached for anonymous users?

I have a form that is pre-populated with information specific to an anonymous user's session information. However, the form appears to get cached for all anonymous users by default. 'Internal Dynamic ...
5
votes
7answers
17k views

How to add reset button to forms?

I've been researching this matter for a while with no clear answer yet. So, here are a few questions ... I'm assuming (correct me if I'm wrong) that Drupal 7 doesn't support reset buttons. It ...
5
votes
2answers
731 views

altering a hook_form_alter function

Is it possible to use hook_form_alter() on a hook_form_alter() function already defined in another module? For example, if I want to alter the output of the following hook from the menu module, can I ...
5
votes
2answers
3k views

What is the difference between hidden and value types in form API?

In Drupal's Form API page mentioned both hidden and value will not display to user. What is the difference between them?
5
votes
2answers
9k views

File upload with ajax

Is there any example how to set up form element with type file to upload it via AJAX. I want to be same as field image in node type article. thx
5
votes
2answers
4k views

Change a normal submit 'input' type to 'button' type with button tag

Is it possible in Drupal 8 to change a regular form submit button from Drupal into a button tag? This is the output I need to achieve: <button type="button" class="search-box__button"> <...
5
votes
3answers
5k views

How to abort the ajax request and redirect in the ajax callback of form element

I want to redirect the page in the ajax callback function, and nothing (like "header", "drupal_goto" etc.) works for redirect in the ajax callback function.
5
votes
2answers
4k views

How to change a node add form without changing the node edit form

I'm using drupal 7 I'm writing a custom hook_form_alter something like this function mymodule_form_alter(&$form, &$form_state, $form_id){ if($form_id == "rating_node_form") { ...
5
votes
4answers
5k views

How do you identify a form element?

I'm still learning Drupal, and I was trying to use hook_form_alter() to resize a text field added from a module. My problem is that I don't think I'm indentifying the element correctly. Here's the ...
5
votes
4answers
7k views

Reset node form after AJAX submit

I have a node form in a block, that is submitted using AJAX. I've created my own callback, because I'm adding the created node to the page if the submission was successful. Now, I want to reset the ...
5
votes
2answers
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'] = ...
5
votes
4answers
3k views

Remove colons from Drupal form fields/labels

How can I remove the : from appearing after every label in forms made with the Drupal Form API?
5
votes
1answer
1k views

Get entity id in hook_form_BASE_FORM_ID_alter() [closed]

I am working on porting a D7 module to D8. As in Drupal 8 all things are represented as entity, menu items are also represented as entity. Now I added a hook_form_BASE_FORM_ID_alter() implementation ...
5
votes
2answers
1k views

How to check spelling of user typed text in a form textbox

I built a form which have a text field for take input from user. Now I want to implement a spell check module or something which can check spell when user type some word or sentence in the text field....
5
votes
3answers
4k views

Custom #ajax “Add another” button only adds 1

This form consists of 1 textfield, and 1 ajax button. I'm trying to make it add another text field with each click. It works for the first one, to get a total of 2 text fields. I cannot get more ...