Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

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
9
votes
5answers
3k views

Webform does not submit, instead redirects to self

My soon-to-be production Drupal site's Webforms have stopped saving submissions; instead it comes back to the same page, complete with the inputted values. I do not have a timeline when it stopped ...
9
votes
2answers
11k views

How to submit webform programmatically with Ajax?

I'm working on an Ajax implementation for the Webform submit on Drupal 7. I was not able to find any good hook to alter the Webform submit button and add '#ajax' in the form so i had a look to a ...
8
votes
2answers
17k 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 ...
8
votes
2answers
19k views

Checkboxes: how do I set the default values or show the user defined values using Form API? [closed]

I am using an checkboxes element within a form in module that I started developing for Drupal 7. This is my first attempt at module development and using the Form API. I am creating a list of ...
8
votes
5answers
4k views

How to add login form to the Access Denied page?

I'm trying to add a login form to the access denied page, and wonder if this is possible via the UI. Any suggestions/ideas?
8
votes
3answers
19k 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 ...
8
votes
4answers
8k views

How can add a textfield to user/register page form in drupal 7?

I want modify and adding a textfield in my Drupal 7 user/register page. I know that the form is generated by the function user_register_form() Can i add a textfield in this way? function ...
8
votes
2answers
9k views

How to implement “Add another item” for custom forms?

I am writing a module which is basically a form that creates a relation between two end points. I want a user to be able to create multiple relations at once. I want to add a button which says "add ...
8
votes
3answers
23k 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 ...
8
votes
1answer
1k views

How to prevent an Ajax form from submitting

The below code blocks any non-ajax form from submitting. $(this.form) .on('submit', function(event) { if (/* Some condition */) { event.preventDefault(); } }); In Drupal 8, how can ...
8
votes
3answers
8k views

Can I attach a jquery.ui.datepicker widget to a form element using the form api?

I have a generic form element: $form['date'] = array( '#type' => 'textfield', '#title' => t( 'Date' ), ); That I want to add the jquery ui datepicker to this element. Is there a way to ...
8
votes
4answers
8k views

add/change div wrapper around specific radio button?

By default, the HTML markup for radio buttons looks like (Drupal 7): <div class="form-item form-type-radio form-item-SOME_ID"> <input id="edit-SOME_ID" class="form-radio" type="radio" ...
8
votes
3answers
10k views

Rendering theme_item_list items

My module provides a simple block which needs to contain an unordered list with some images. From a block function, I am returning a renderable array: $block['content'] = array( 'list' => ...
8
votes
2answers
9k views

How to upload file in drupal8 forms with form element type file?

I want to upload a file and I have to use form element type as 'file'. In submit function I am not able to get any proper data related to the file which I am uploading. SO Can anyone please help me to ...
8
votes
2answers
5k views

krumo()/dpm() not working

I have a custom module and a template to alter the appearance of my node submission forms, á la these instructions. My module consists of three functions: A hook_form_alter() that works fine A ...
8
votes
1answer
9k views

How to Use Ajax in form alter in Drupal 7?

I have created a content type named "main menu". I have few select lists which depend on one another. I wanted to display a different list when different checkboxes are selected. I figured out that I ...
8
votes
2answers
12k views

Multiple forms on single page?

Is it possible to put multiple forms on a single page? I am trying to make a coupon offer page. I wanted to have two forms for two different offers on each side of a page. Each form has a text field ...
8
votes
4answers
6k views

Delay ajax call on textfield to allow for typing

I would like to delay ajax from firing in the same way that the autocomplete seems to work. For example, if a user it typing, the ajax will not run until 500ms has elapsed since the last keyup. I am ...
8
votes
2answers
3k views

How to cache forms with a reverse proxy and deal with stale form tokens?

When Form API generates a form, it also generates a token that is passed out with the form in a hidden field, and expected to be returned back. If it is, the form is processed. If a rendered form ...
7
votes
6answers
13k views

How do I use Font Awesome on a form submission button?

So I've got Font Awesome working on my Drupal 7 site. I'm not using the Font Awesome Drupal module. I'm just declaring the style sheet in the template.php. function genchstyle_preprocess_html(&$...
7
votes
4answers
7k views

How to create hook for altering every node form?

I tried: mymodule_form_node_alter mymodule_form_node_form_alter and global hook: function mymodule_form_alter(&$form, $form_state, $form_id) { if ($form['#id'] == 'node-form') { ...
7
votes
4answers
7k views

Debugging #AJAX and FormAPI

What is the easiest way to view current '$form_state' variables while working with #ajax? is there a way I can get dpm() to update automatically on each ajax load? If it matters, I'm testing ajax on ...
7
votes
2answers
3k views

Verify a node with a given node ID exists

I created a module that receives the node ID from the form. On form validation, it needs to verify a node with that node ID exists. How can I verify it?
7
votes
3answers
9k views

How do I programmatically generate an entity form?

I need to programmatically generate the entity form for my custom entity - basically get the same output that happens when you call \Drupal::formBuilder()->getForm('form namespace') When I try ...
7
votes
2answers
5k views

Multiple form on module page

i created a module. I created a form and implemented it on the page: function tudakozo_menu() { $items['tudakozo'] = array( 'title' => t('Tudakozo'), 'page callback' => '...
7
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"> <...
7
votes
2answers
14k views

Hide text field in hook_form_alter

I have a field field_agent_name. I want to hide this field in my custom module using hook_form_alter. How to do this.
7
votes
5answers
12k views

how to overwrite the search box?

<div class="fr_search"> <form action="/" accept-charset="UTF-8" method="post" id="search-theme-form"> <input name="search_theme_form" id="edit-search-theme-form-1" size="...
7
votes
2answers
4k views

how to remove password confirmation field in user registration form?

I want to remove password confirmation field. Its ok if user enters the password only once. There is no need to confirm it again. I am using this code <?php function dp_form_alter(&$form, &...
7
votes
4answers
10k views

How to disable the title field on the node edit form?

How can I hide or disable the title field on the node edit form? If I do so from the content type Manage form display tab (admin/structure/types/manage/CONTENT_TYPE_MACHINE_NAME/form-display), then I ...
7
votes
1answer
3k views

Embed controls 8 #table element?

I'm using the Drupal 8 #table element to populate a table on my form, and it's working great for displaying static data. foreach ($entries = getData() as $entry) { $row = array_map('Drupal\...
7
votes
3answers
3k views

What is correct selector for radios to determine if ANY radio is selected?

Using #states to change form element visibility, I would like a 2nd element to be visible only if the 1st element is filled in. The first element is a pair of radio buttons, so I tried: '#states' =...
7
votes
1answer
5k views

Print the comment form with PHP

I'm trying to print a comment form with the following code. <?php print drupal_get_form('comment_form', array('nid' => $row->nid), t('Post new comment')); ?> All I get is the ...
7
votes
2answers
10k views

How to customize the user login form?

I'm trying to customize user login form in /user/login page and I want to use a hook_form_alter function to add some awesome style and placeholder to each of user login form fields and remove or hide: ...
7
votes
1answer
3k 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,...
7
votes
3answers
13k 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 ...
7
votes
2answers
20k views

“#markup” form element can't have children

I have my form, but any child of the "#markup" element will not appear when the form is being rendered. $form['html'] = array( '#type' => 'markup', '#markup' => '<h2>My Heading</h2&...
7
votes
4answers
4k views

Redirect a user after the node has been saved

I'm looking for a hook to use after a node of a specific content type is created or saved, to perform a redirection to a specific page.
7
votes
2answers
9k views

Add link field in custom form

I want add link field (label + url internal/external) in custom form This not work: $form['test_ink'] = array( '#type' => 'link', '#title' => $this->t('Link title'), '#url' => '', )...
7
votes
3answers
8k 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 ...
7
votes
1answer
4k 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 ...
7
votes
1answer
3k views

Form API image preview

I've read many discussions about image preview in fapi with 'managed_file', but I can't find a conclusive answer on how to do this properly in D8. An obvious solution would be to reuse Drupal\image\...
7
votes
2answers
506 views

Creating an alternative login page other than /user/login

I have managed to do this in Drupal 7 with the following code: function my_special_paths_menu() { $items['authenticate'] = array( 'title' => 'Log in', 'page callback' => '...
7
votes
4answers
6k views

How do I embed a node creation form inside a view

I have a View with some fields and a couple of link items. What I want to do is when I click on the link items, a node creation form associated with link should appear inside the view (the AJAX way). ...
7
votes
3answers
7k views

Multiple submit buttons: Which one was pressed?

This may be a duplicate of the following: Multiple form submit, but I am unable to figure out how the answer applies to my situation. So here is my go at asking this (I admit) quite similar question: ...
7
votes
4answers
11k views

Is it possible to redirect after “pushing” a file to the user?

I've got a setup where a site generates internal analytics about site usage. Users are able to request a download of their personal analytics, and because this information is sensitive I do not create ...
7
votes
4answers
3k views

How to remove the default “Anonymous” from comment author name?

In the comment form field (core comment module) I would to leave the comment author name empty, in order to encourage commentators to come up with original epithets. What's the easiest way to do it?
7
votes
1answer
405 views

Memcache and form cache - is specfiying database for form cache still necessary?

In Drupal 7, a typical setup for Memcache API and Integration was to add this into your settings.php: $conf['cache_backends'][] = 'sites/all/modules/memcache/memcache.inc'; $conf['lock_inc'] = '...
7
votes
2answers
5k views

Managed file: What is the proper way of setting #default_value?

$form['picture']['file'] = array( '#type' => 'managed_file', '#title' => t('picture'), '#description' => t('Allowed extensions: gif png jpg jpeg'), '#default_value' => (isset($foo-&...
7
votes
1answer
9k views

How to test if honeypot is working on a form?

I have applied the Honeypot module to my site and set it to protect all forms on the site. The problem is I am unsure of how to test it to know that it is working as expected. Can anyone tell me how ...