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
-1 votes
0 answers
10 views

How to send message for selected users on their mail using custom module? [duplicate]

This is my table This is my code Form namespace Drupal\custom_table_users\Form; use Drupal\Component\Utility\EmailValidator; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; ...
user avatar
0 votes
0 answers
21 views

How can I send message for selected users on their mail using custom module?

I need to select a user or several users, after which, I need to enter the text in text-area and press the submit button so that the message is sent to all selected users by email. This is the form ...
user avatar
0 votes
1 answer
36 views

getStorage() on null when using entityTypeManager in form

I'm trying to use dependency injection correctly in a custom form but I'm getting an error when trying to access entityTypeManager. <?php namespace Drupal\my_module\Form; use Drupal\Core\Form\...
user avatar
-2 votes
0 answers
20 views

Block an email address in the contact form [closed]

What is the best practice for blocking a specific individual email address in the contact form that comes in Drupal core? It seems that most of the spam comes from a handful of gmail addresses. These ...
user avatar
  • 149
0 votes
0 answers
19 views

Displaying a taxonomy term description in the select list

Select lists have a name|value pair structure. In the case of taxonomy tid|term name. In order to make data entry faster, people would like the term name in the select list to include the description. ...
user avatar
  • 1,359
0 votes
1 answer
30 views

Multistep Ajax form with ManagedFile: current step array dissapears from $form upon file upload callback

I have a custom multi-step Ajax form. On the second step, I have defined a managed_file field where users can upload several attachments: public function buildForm(array $form, FormStateInterface $...
user avatar
0 votes
1 answer
13 views

What is the proper way on submit of a config form to save its fields if #tree = true?

With a config form, when saving the fields in the submit, rather than ->set('FIELD NAME', $form_state->getValue('FIELD NAME') how would a form with #tree = true be handled? For example: $field[...
user avatar
0 votes
0 answers
27 views

Redirect after using the one time login after password reset

How can i programmatically change the button link destination after clicking the one time login button in drupal 9: I've tried this solution but got stuck because i didn't know how to compare a link ...
user avatar
  • 11
1 vote
0 answers
38 views

Add javascript supplied form values to an options list

I have a form, which the user inputs certain data into. In the form is an empty, (and initially hidden) select list. Once certain data has been entered, a javascript that polls the website, which in ...
user avatar
  • 27.4k
0 votes
0 answers
13 views

Custom #upload_validators not firing

I have the following code but the custom validator is not being fired when I add a file to the file field. If the file isn't a csv then I get an error message but if I upload a csv then the second ...
user avatar
0 votes
1 answer
34 views

How to add parent terms of a taxonomy term?

On my Drupal 9 site, I have an "Article" content type with a taxonomy reference field_tags. This field is configured so that the user can choose the appropriate term from a drop-down list. ...
user avatar
  • 1
-1 votes
1 answer
30 views

Using List(text) how not have a default value?

The first entry in the List(text) field is the one that is chosen as the default. How do we ensure that an item is selected? The field is Deal Type field_bond_deal_type List (text) The widget is ...
user avatar
  • 1,359
0 votes
1 answer
39 views

Trim or strip spaces around the email or username on the login page [closed]

I know that my Drupal installation (9.3.15) doesn't trim spaces at the login page (form id: user-login-form). I have some code in the HOOK_form_user_login_form_alter but in that place in $form_state I ...
user avatar
  • 239
0 votes
1 answer
34 views

First checkbox is always checked in config form

I'm making config form with checkboxes and I'm always getting first checkbox checked. But in Kint debug it is not checked: Here is part of my code: $user_roles = $this->entityTypeManager->...
user avatar
  • 1
0 votes
1 answer
22 views

Use #state with taxonomy reference field (multiple terms)

If we add a “taxonomy” reference field, we have a field in the form that lists the terms. If I dump $form, I get for this field: field_zone" => array:7 [▼ "#type" => "...
user avatar
0 votes
0 answers
9 views

add prefixes and suffixes to taxonomy terms in hierarchical taxonomy vocabulary with hook_form_alter()

Is it possible to add prefixes and suffixes to taxonomy terms in hierarchical taxonomy vocabulary with hook_form_alter(). For example : Category A - Category A1 - Category A2 Category B - ...
user avatar
1 vote
0 answers
44 views

How can we add HTML (Font Awesome Icon) to a form's submit button?

We have used hook alter to customize a form's submit button but any HTML added is ignored. How can we add HTML to a form's submit button so that we can insert a font awesome icon? For example, in the ...
user avatar
0 votes
0 answers
37 views

Multiple ajax form not working on whole site

I have multiple pages which contains multiple ajax forms. When I am working on a particular form, its ajax submission is working. But at that moment, if I go to second page form, ajax submission not ...
user avatar
-2 votes
1 answer
24 views

Custom textfield element, different $form_state value and element '#value' value

I have a textfield element (named 'bus_station'), which holds a bus station name. I am looking for a way to create a custom 'bus_station' element (possibly extending Textfield class), which would: ...
user avatar
0 votes
0 answers
26 views

Fields in content form are below save button

I got a problem in drupal 7.x which is that i'm trying to edit and create content from a content type that has 140+ fields and the save button section has fields below it as shown in this image: I ...
user avatar
2 votes
1 answer
49 views

Disable a field if another field is disabled

I need to disable field A if field B is disabled too. Actually, my current field A has the following #states (altered using hook_alter_form) to disable it if field B or field C are empty: /** * ...
user avatar
1 vote
1 answer
85 views

AJAX in a plugin form results in "The specified #ajax callback is empty or not callable."

I have a configuration form for a Condition plugin I want to have ajax in. When selecting from this field, I want to get a list of displays for that View: public function buildConfigurationForm(...
user avatar
  • 26.5k
0 votes
0 answers
22 views

Creating links in TableSelect rows

I've created a module which defines a Form, but when I try to add a column of links, it is empty when I set the '#type' to 'link'. I am testing this on Drupal 9.3.x. On the surface, this is the same ...
user avatar
0 votes
1 answer
15 views

Changing the Moderation State Control Box input to a textarea

I wanted to change the moderation state control box input to a textarea like the image below shows. Currently the input only supports 128 characters but I believe log messages can hold much more in ...
user avatar
  • 629
0 votes
0 answers
8 views

How can i get the fields of a view which has contextual filter inside views_view_field hook in drupal 9?

I have a drupal 9 site. I have a parent view A and a child view B. I am using views_field_view contrib module in order to pass an id from view A to view B. I have added a contextual filter in B to get ...
user avatar
0 votes
1 answer
41 views

How to refresh and reload (with ajax?) order checkout panes and order calculation independent from commerce cart refresh (e.g. billing address change)

I have following problem: During checkout, my customer has to fill in his billing address (at least at the first time) to calculate VAT rate and gross price. Further calculation is done via an order ...
user avatar
  • 129
1 vote
0 answers
29 views

Change the state of a checkboxes field

I know how to use conditions with Form API for fields like text-field, checkbox, for example, showing or hiding a field when a checkbox is checked. $form['lorem'] = [ '#type' => 'checkbox', '#...
user avatar
0 votes
1 answer
54 views

How to add a submission handler to a form class on Drupal 8?

I would like to add a submission handler to my form class so that the submitted values are saved. The parent class does not save them but only displays a message. I use Drupal 8! Here is my form class:...
user avatar
0 votes
0 answers
20 views

How to persist webform validation result in multistep ajax webform handler?

In my AJAX form the user has to do a validation as he needs a code to enter the rest of the form (it has 3 pages or more). I have an handler to validate this and this same handler uses that code to do ...
user avatar
1 vote
1 answer
41 views

How to add an unique wrapper id to a widget element?

I made a widget that "generates" fields based on the option chosen of a select field. I got most of the logic done: 1- An option is chosen from this field: $element['value'] = [ '#type' =&...
user avatar
0 votes
1 answer
25 views

Clear field value when edit node

I have a List (text) field in a content type that will determine the importance of the content whether it is Major or Minor and that field is set to be required. I need to force content editors to ...
user avatar
0 votes
1 answer
67 views

Can I add elements to a field widget with AJAX?

I want to add fields depending on the first option selected. I also made a form with a similar behaviour but it wasn't a field widget. I used this module as an example to make the form I'm not sure if ...
user avatar
0 votes
0 answers
30 views

hook_form_alter makes js on every other form not work

I use hook_form_alter() to alter a field. function mymodule_form_alter(&$form, &$form_state) { if ($form['#id'] == 'my_form') { $form['my_field']['#value'] = 'New value'; } } It ...
user avatar
  • 133
0 votes
0 answers
44 views

State API doesn't work on new paragraph fields

I have programmatically added #states into fields in a paragraph works fine for existing fields in a form. But on clicking add more button on paragraph to add more fields the hidden fields show up. I ...
user avatar
  • 15
0 votes
1 answer
26 views

How can I alter an order item field depending on inline entity form (IEF) validation?

I extended my order item type with an additional boolean field. Before the order item gets submitted via "order edit form" (/admin/commerce/orders/{order_id}/edit), it should be validated ...
user avatar
  • 129
2 votes
1 answer
56 views

Can't preselect time zone in hook_form_alter

I'm writing a custom installation profile/distribution and I want to pre-populate some fields in the 'Configure Site' form (/core/install.php). I have managed to prefill/preselect other fields like (...
user avatar
  • 239
0 votes
1 answer
47 views

How to change the label of an image's title field in a paragraph

In a paragraph I have an image field for which the title field is enabled and required. I need to alter the label of this title field to replace "Title" by "Caption" I tried to use ...
user avatar
  • 692
1 vote
1 answer
29 views

What is the correct way to set language used by a modal form?

I have a button linked through a controller to open a custom form in a modal: The controller callback is: /** * Callback for opening the modal form. */ public function openShareLinkModalForm(...
user avatar
  • 907
1 vote
1 answer
35 views

Compress file with ArchiveInterface without file paths

I'm trying to create an archive of log files to be downloadable in a form making a custom module in Drupal 9. In the form, the user can change the format of the archive, as per image: Here below my ...
user avatar
  • 93
0 votes
1 answer
46 views

How do I skip calling a custom validation function in a form with AJAX dropdowns?

I am using headless Drupal with .NET middleware. I have a Drupal 9 form. This form contains two drop-down elements which are filled up depending on a value selected in a third drop-down. I have a ...
user avatar
0 votes
2 answers
39 views

Checkout Flow Submit Pane Form Checkbox to Boolean Field

I create a Checkbox in the Checkout Flow, CheckoutPane. How i can send the Value of the Checkbox to a Entity in the User-Profile or the Order. Description: I need a Checkbox in the CheckoutPane, when ...
user avatar
1 vote
1 answer
120 views

Multiple forms on page

I am trying to get multiple forms to work in a views display. All of the forms uses AJAX, but they appear to be interfering with each other. One form is the Views Bulk Operations form that turns the ...
user avatar
  • 161
0 votes
0 answers
52 views

Using FileSystemInterface::EXISTS_REPLACE in a form to replace files if they already exist

I have a form set up in the admin menu that allows a person to upload a file, like a picture. That file is then used in the custom module elsewhere. I want to be able to replace that file if they ...
user avatar
  • 25
-3 votes
1 answer
64 views

How do I read element attribute from $form_state?

I am trying to hide entity id from my autocomplete fields. I downloaded a jquery script that removes the bracketed id and updates the autocomplete element with the new element. It then writes the ...
user avatar
0 votes
2 answers
24 views

How do I dynamically (AJAX) show radios in form API?

A form like the following is expected to show additional fields when user selected "Yes" in the "Show more" radio button. When shown, the more section has a "Name" text ...
user avatar
0 votes
1 answer
50 views

How to get exposed filters for entity reference to render?

I am using a entity reference view and I am able to filter via taxonomy terms directly, but when I set it to exposed and let the user decide, it does not display on the form. How can I get the expose ...
user avatar
  • 367
0 votes
0 answers
38 views

How do you add a filter with manage form display?

So I know with form display, you add fields to the content type which then can be re-arranged under form display. But what about more complicated features, like filtering via taxonomy terms? I know ...
user avatar
  • 367
0 votes
1 answer
45 views

Why a form doesn't keep the value created during construction

Here is a form using DI for $this->entity_type_manager There is also a radio-button with Ajax (I have added the code as it is maybe the reason of my problem) class myForm extends FormBase { ...
user avatar
  • 554
0 votes
0 answers
66 views

How to add checkbox using hook_field_widget_WIDGET_TYPE_form_alter()

Running Drupal 9 with paragraphs module, paragraphs collapsible and paragraphs jquery ui accordion installed. I wish to modify paragraphs' form, specifically where it displays private files by adding ...
user avatar
0 votes
1 answer
71 views

How can I set a default value to show for a taxonomy term name in its edit form?

I have a site where I have a taxonomy term. I want to set a default value to the term name and display it when the form loads. In hook_form_alter(), I tried to set the default value to Check term name ...
user avatar

1
2 3 4 5
135