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
0 answers
11 views

Fields not required for certain roles when click on ajax

I want to not required fields when i click on the certain roles When click on the roles it checks if those roles are those that i want the fields not to be required. It is working fine but there is ...
Gaurav Gupta's user avatar
0 votes
1 answer
58 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
40 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
1 answer
69 views

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

I want to use getString method instead of [0]['value'] how do i do that if possible and is there any other way? -This is the array i am getting when dump their values dump($form_state->getValue(...
Gaurav Gupta's user avatar
-1 votes
0 answers
31 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.7k
-2 votes
0 answers
53 views

How do i get all the fields just below there respective types when click on their respective checkbox in form?

I have to create a drupal10 custom form -> In this i have created a checkbox with all the content types and when i click on any of the content type the ajax callback occurs which fetch the ...
Gaurav Gupta's user avatar
1 vote
0 answers
37 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
88 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
73 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
0 answers
38 views

How to run batch in modal

How to run batch in modal I have rendered link "Run batch" at twig level, click on it form open in modal click on submit button batch run, but it's redirected to batch page Desired ...
mini's user avatar
  • 682
0 votes
1 answer
21 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
29 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
-1 votes
0 answers
56 views

How to create and return a file generated by mPDF from a form submit?

I want to create a demo pdf after a form submit. I have used mPDF library and run composer require mpdf/mpdf to install it. Currently the library is installed in ROOT_FOLDER/vendor/mpdf. Now I have ...
Souvik Das's user avatar
0 votes
1 answer
58 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
112 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
54 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
42 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
61 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 ...
ewik's user avatar
  • 15
0 votes
1 answer
54 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
33 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,224
0 votes
0 answers
51 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
97 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
50 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
36 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
1 answer
77 views

How do i fetch the data from ajax callback by clicking on checkbox and show it in the checkbox?

I have to create a drupal10 custom form -> In this i have created a checkbox with all the content types and when i click on any of the content type the ajax callback occurs which fetch the ...
Gaurav Gupta's user avatar
0 votes
2 answers
65 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
64 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 ...
ewik's user avatar
  • 15
1 vote
1 answer
47 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
113 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
31 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
30 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
46 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,079
1 vote
0 answers
34 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,079
0 votes
1 answer
32 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
50 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
35 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
  • 570
1 vote
1 answer
99 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,224
2 votes
2 answers
67 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,791
0 votes
0 answers
35 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
0 votes
0 answers
104 views

Set form values based on ajax callback

I am creating a complexed multistep form based on data from an Excel document. The user can save parts of the form using AJAX save buttons and updated data from the Excel document are displayed in the ...
NicklasF's user avatar
  • 289
1 vote
1 answer
55 views

Set error message only on errornous field(s) when validating multiple instances of the same field

I have a form where the users can add one or more "units". I want to validate and return an error message on the problematic field when the unit does not have a value "leader" With ...
John Doe's user avatar
0 votes
0 answers
53 views

Form States not working when compressed javascript is enabled

I have visible states setup for a 2 fields that correctly work when javascript aggregation is disabled. When I turn JS aggregation on both fields are visible no matter what option I select on the ...
blu's user avatar
  • 438
0 votes
1 answer
40 views

is it posible to get the value of other fields right inside the buildForm() method without having to save configuration?

I have a config form with two select fields. The first one(vocabulary) gets populated automatically without problems with options taken from the available vocabularies for users to pick up one. The ...
Jorge Luis Arzola's user avatar
1 vote
2 answers
54 views

functional test: Schema errors but Schema is correct

I have a settings form in my custom module and functional test of this form. I added new field to form $form['unblockable_roles'] = [ '#type' => 'checkboxes', '#title' => $this->t('Users ...
Vanish's user avatar
  • 166
0 votes
0 answers
72 views

Ajax callback not returning options for checkboxes

I'm triggering an ajax callback on change event of a dropdown, this method returns additional form elements like text fields, number and checkboxes, but for checkboxes the options are not appearing at ...
Himanshu Lahare's user avatar
4 votes
2 answers
202 views

How can I add inline markup to submit buttons?

I migrate code from Drupal 7 to Drupal 10, in Drupal 7 I often created buttons with an icon and text like showen aboven: Drupal 7 code: $form['submit'] = [ '#type' => 'submit', '#value' => t(...
chris's user avatar
  • 61
0 votes
0 answers
81 views

how to add the "alt" attribute to a "managed_file" type image field

I have a custom form in drupal 9 where I am creating a managed_file type field to upload an image: $form['footer']['logo'] = array( '#title' => 'Logo', '#type' => 'managed_file', '#...
Juan Carlos Osorio's user avatar
0 votes
0 answers
75 views

How can I uncheck checkbox fields during form's validation?

We have a Drupal 9 custom validaton hanlder where we need to remove all checkboxes from a multi-value term reference field. I can clear/change other field types but not this one. We tried the ...
quantumized's user avatar
  • 1,177
0 votes
0 answers
19 views

New message causes a fatal error

I am facing following error in logs and white screen on sending new message through Private Message Module (Open Social Distribution 11.9.4). Drupal\Core\Entity\EntityStorageException: Parameter &...
tt12's user avatar
  • 1

1
2 3 4 5
137