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
0 votes
1 answer
5 views

Create input name from array like #parent

I'm just wondering if there is a Drupal way / helper function to build input[name] string from array. So I have an array '#parents' = ["info","variation-555-1","example",&...
Dylan's user avatar
  • 428
1 vote
1 answer
25 views

How to get entity object in buildform formbase?

I've the following in my routing.yml project.product_elasticsearch: path: '/product/{commerce_product}/elasticsearch' defaults: _form: '\Drupal\mymodule\Form\ProductElasticsearchForm' ...
Sivaji's user avatar
  • 2,476
0 votes
0 answers
15 views

How do I render TH for individual rows of a table?

In the example below, how do I make a1 and a2 into <th> instead of <td>? I want an html table like: <table data-drupal-selector="edit-test" id="edit-test" class=&...
Kevin Finkenbinder's user avatar
0 votes
0 answers
36 views

'#empty_option' not working for nested select list

I have a form with several select lists, the select lists that are not nested show the "#empty_option" as expected, but the ones in a nested container do not work. Expected output: the "...
Kevin Finkenbinder's user avatar
0 votes
0 answers
39 views

Why isn't Messenger working as expected in my submitForm?

I have this custom form (which is a tableselect): In the submitForm, there are two possible cases: The user has already made a reservation and a warning message is displayed: The user makes his ...
gbmapo's user avatar
  • 1,066
0 votes
1 answer
53 views

How to inject extra data into entity reference checkbox form widget

I've a taxonomy tree used in an entity reference field, which requires some custom rules (e.g. if any option of subtree A is chcked, then any option of subtree B is disallowed or if any option of ...
Hudri's user avatar
  • 5,484
0 votes
1 answer
71 views

Programmatically updating a Webform submission with a file element doesn't remove the attached files

I am using Drupal 9.3 and Webform 6.1.7. I have a Webform that contains a file element and am building a custom form to update the submission data. I have found that when I submit my custom form I can ...
inertiahz's user avatar
  • 193
0 votes
0 answers
32 views

Can i add my custom user field to a user mail template? [duplicate]

I added a custom user field (/admin/config/people/accounts/fields) with machine name field_about_user to my D9.5 site (yes i know, it needs updating...). Now i tried to add that field to the Mail ...
sirtet's user avatar
  • 63
2 votes
0 answers
20 views

jQuery timepicker on custom FAPI form element

How can i add jQuery timepicker to custom form element. There is some description on API docs: #date_time_callbacks: An array of optional callbacks for the time >element. Can be used to add a ...
Ev Tr's user avatar
  • 21
0 votes
1 answer
44 views

What is the calling method of validateForm callback of a FormInterface subclass

i just want to know where in the drupal code the validateForm method is called from the FormBuilder. In the doValidateForm of FormValidator class i don't see the callback being called ! Can you give ...
Frédéric Hébert's user avatar
0 votes
0 answers
47 views

How to add a description(alternate text) for a custom file field created

I have to a description text field a file field created in form alter $form['test_file'] = [ '#type' => 'managed_file', '#title' => t('File Upload'), '#...
Aziya's user avatar
  • 11
0 votes
1 answer
38 views

how to get the default value for a multivalue field

I'm using the Mulitvalue Field module (https://www.drupal.org/project/multivaluefield) and I created a form like this and it successfully sets the various emails into the configuration file, but when ...
Diana's user avatar
  • 3,290
0 votes
1 answer
34 views

How do I link to a custom form mode in a (node) tab?

My issue is my form is too big and too slow, with nested paragraphs, media entities and so on, the biggest issue is the metatag-module with its 100s of fields. So I thought I just add a new form ...
Stephan Steege's user avatar
0 votes
1 answer
41 views

CKEditor returns a value as array

In my Form I have this entry that presents a CKEditor instance $form['notes'] = array( '#input_format' => '1', '#rows' => '5', '#type' => 'text_format', '#base_type' => '...
Cy Jobes's user avatar
0 votes
1 answer
100 views

How to make #description appear on a field widget?

I have a custom field widget that extends WidgetBase. My formElement method looks like this: public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, ...
JAyenGreen's user avatar
0 votes
1 answer
75 views

How to add a reset button to forms?

How do I add a reset button to a form? I have a form with a CKEditor and other fields, plus hidden fields. How do I reset the form so all fields are empty?
Cy Jobes's user avatar
0 votes
0 answers
70 views

What's the standard way of passing a return URL to a form?

The scenario is simple. I've constructed a Link object whose URL points to a form. I need a way to pass a URL to that form so that proper redirection can happen after the form is submitted. Passing a ...
ilechcod's user avatar
  • 113
-1 votes
2 answers
120 views

How can I compare date time values in a content form?

I want to use getString() instead of [0]['value']. How do I do that, if it possible? Is there any other way? This is the array I get when I run this code. dump($form_state->getValue('...
-1 votes
1 answer
43 views

How to use the Tableselect element for an order-able list of items?

It's been a minute since I have used tableselect. I want to present a user with a list of sortable options that have checkboxes to indicate they are on or off. See this screenshot: While the table ...
Kevin's user avatar
  • 27.8k
1 vote
0 answers
85 views

How can I create a custom "Add to cart" form?

I'm developing a basic Commerce shop with Drupal 10. The product type is clothing, which has a single product variation (product_size) and three different product attributes for that variation. The ...
SlowCheetah's user avatar
0 votes
1 answer
158 views

Make a custom action with form

I am trying to make a custom user action where the selected users will have a node created manually, however I need to create a form to save the data that this node will have, such as: title, start ...
Juan Carlos Osorio's user avatar
0 votes
1 answer
76 views

missing form tag while embedding and stylizing form elements

I am wanting to embedd a form into a twig template, but place the elements where and how I want them. The idea is to have better control over the layout without having to use the $form array to ...
Cy Jobes's user avatar
0 votes
1 answer
28 views

Prepopulating a drop-down select box that references another entity

I have a node create form for content type "space" so that the URL looks like https://.../node/add/space. In this page, there is a form with a drop-down select that corresponds to an entity ...
BMM's user avatar
  • 103
0 votes
0 answers
31 views

Filtering dropdown selectable values depending on the selected value on another dropdown - in a content creation page

I have 3 content types: "Floors", "Spaces" and "Resources". One floor can have multiple spaces, and one space can have multiple resources. "Floor" has only a ...
BMM's user avatar
  • 103
0 votes
1 answer
204 views

How to use 'required' and 'optional' states with form api when using a select field?

I'm trying to create a form in Drupal 10 that will show an field that is both visible and required depending on the selection of a radio input that comes before it. The visible state seems to work ...
blu's user avatar
  • 438
0 votes
1 answer
133 views

Why is my message not showing for anonymous user?

In a custom form, I have this Ajax submit: public function ajaxSubmit(array &$form, FormStateInterface $form_state) { $response = new AjaxResponse(); if ($form_state->hasAnyErrors()) ...
gbmapo's user avatar
  • 1,066
1 vote
0 answers
67 views

How can I have both file download and redirection in for submit?

I have this form submit: public function submitForm(array &$form, FormStateInterface $form_state){ // File download $sFileName = 'JdP-Adhesion.pdf'; $sFileNameWithPath = 'sites/default/...
gbmapo's user avatar
  • 1,066
1 vote
0 answers
69 views

Alter the address fields of the address module like adding a placeholder

I made a form with the FormAPI to update the address fields of the address module (with Drupal commerce) and it works well. But I saw a topic where you could generate the form with an address type ...
Sébastien Gicquel's user avatar
-1 votes
2 answers
113 views

How to add a link to table row?

There is a field 'field_upload_artwork' that contains files. I am using them to build links to files and want to insert links after Apparel Printing in the last step of the form. Now the markup in ...
nathan111777's user avatar
0 votes
1 answer
62 views

Why doesn't my completion message show?

I have this form to handle a custom content entity: created by this code: public function buildForm(array $form, FormStateInterface $form_state, $contractId = NULL) { Some code to inialize ...
gbmapo's user avatar
  • 1,066
1 vote
1 answer
55 views

How to add extra validate hook to the order information form?

I am trying to collect additional information on checkout to add to the order. I have added new fields to the order entity and then used hook_form_commerce_checkout_flow_multistep_default_alter to add ...
liquidcms's user avatar
  • 1,248
0 votes
0 answers
68 views

TriggeringElement not working properly for my ajax form

<?php namespace Drupal\demo\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Component\Serialization\Json; use Drupal\node\Entity\Node; use \Drupal\...
Z CHAMP's user avatar
  • 62
0 votes
1 answer
120 views

Why does Ajax prevents managed_file to be displayed?

I have this form created by this code: public function buildForm(array $form, FormStateInterface $form_state, $contractId = NULL) { some initialisation code... $database = \Drupal::database(...
gbmapo's user avatar
  • 1,066
0 votes
0 answers
58 views

massageFormValues not being run on custom form

I've built a widget for my custom field and this works OK when I create / update a "normal" node edit via the normal D10 content interface & forms. I've added this widget to a custom ...
Alex Monaghan's user avatar
0 votes
1 answer
74 views

How to update migration field mapping using custom module/form?

I was learning about Drupal migration recently and found out that we can use Migrate Plus module to import migrations as configurations. Hence I started wondering if a migration is imported as a ...
SGupta's user avatar
  • 1
0 votes
2 answers
97 views

How to do Do a redirect in buildForm()?

I send a link to a URL by email. This page is created with a controller which contains a form (FormAPI). I pass a token as a parameter to secure access to this form. So I check if this token exists ...
Sébastien Gicquel's user avatar
0 votes
1 answer
107 views

How to get $form_state->getUserInput() ( i.e, what the user entered in the input ) in each inline entity form and not only in the first one?

I use the Inline Entity Form module to build nested multiple forms. I have a design form in which there is an inline form - garment. And inside the garment form, there is a product field. In the ...
nathan111777's user avatar
1 vote
1 answer
51 views

How to create a page with a specific form display?

And how do form displays work? I have a content type (Sketch) with an image. As an authenticated user, I can create a node of that type from /node/add/sketch, but that uses the default form. How do I ...
Victor Pudeyev's user avatar
1 vote
1 answer
117 views

Form states API configuration first page load not working

I would like to show a text field when a checkbox is checked and a specific option is selected in a select list The form works fine when there are no values in and the form is loaded but doesn't work ...
Daniel Harper's user avatar
1 vote
1 answer
64 views

How to enable WebP upload to a custom form's managed_file input

This question is not about image styles, which are all already configured to accept WebP. Our theme uses a custom form with elements like $form['cta1']['fp_cta1_background'] = [ '#type' ...
lynxlynxlynx's user avatar
0 votes
1 answer
54 views

Is there a trick to hide the time portion of a date-time field in a form?

I have some fields that are "Date and time". I want to ignore the time portion and only solicit date portion from the user. However, since there is already have data in these fields, Drupal ...
VardeVim's user avatar
0 votes
0 answers
86 views

How can I programmatically set the options for a views exposed filter?

While it is possible to use hook_form_FORM_ID_alter() to programmatically set the options for any select input, with a views exposed filter there is the added complication of not knowing how Drupal ...
arnoldbird's user avatar
  • 1,173
1 vote
0 answers
39 views

How to determine what values to set when preprocessing views exposed filter options?

When we set options for a views grouped filter using the views GUI, the select input's option values do not match the values we set in the GUI. For example, if we use the GUI to set the Grouping 1 ...
arnoldbird's user avatar
  • 1,173
0 votes
1 answer
45 views

How to hide terms from entity reference field on node form

I've been searching quite a bit on this already and was not able to find a solution. installation is d10 So on my node I have an entity reference field which is showing Taxonomy terms. Two of those ...
arnemichiels's user avatar
0 votes
1 answer
19 views

When providing default settings for elements in a field widget, what is the syntax for multiple value checkboxes?

I have a field widget with three different settings, two of them are just string values but the third is multiple checkboxes. This page describes how to set default settings, simple enough for integer ...
Problue Solutions's user avatar
0 votes
0 answers
51 views

Node save button can be clicked while there is still running javascript which leads to unexpected behavior

We have Group module installed and a custom field. To be more specific, we can set a value of this field from a dropdown list depending on the selected group. The behavior is as follows: Open content ...
Eiki Hanai's user avatar
0 votes
0 answers
41 views

How to fire the autocomplete after input reach 3 characters

I am setting a view for the autocomplete feature of a widget with the following code: function my_module_field_widget_entity_reference_autocomplete_form_alter(&$element, FormStateInterface $...
Baud's user avatar
  • 532
1 vote
1 answer
207 views

Modal form opened from modal form doesn't submit

I have a user form mode (like node view mode except for forms) opened in a modal. When this form is submitted the user entity is updated and the modal is closed. This works fine. I now want to extend ...
liquidcms's user avatar
  • 1,248
2 votes
2 answers
79 views

How to access validated values after AJAX callback when fields are nested in a container?

I have a custom form where I have a search field and button. After the users clicks the button, I load some items based on what they've entered into the search field. The problem that I'm having is ...
sonfd's user avatar
  • 7,881
0 votes
0 answers
38 views

Inline Entity Form - is it possible to add field from child entity's taxonomy reference field

I have the below structure on my Drupal 9 site: Product content type -- field_product_integration (references contents of type Integration) Integration content type -- field_product_feature (...
Ashok Negi's user avatar

1
2 3 4 5
137