Questions tagged [forms]
Use it for questions about the Form API. Don't use it for entity or entity field forms.
6,849
questions
-1
votes
0
answers
15
views
Is there a way to get $response->addCommand(new RedirectCommand($url)); to execute after a set number of seconds?
I'm using Drupal's Form API. In one of my ajax calls, I have a RedirectCommand to redirect to another page.
Is there a way to get $response->addCommand(new RedirectCommand($url)); to execute after ...
0
votes
0
answers
85
views
Form storage values are not persisted when validation fails
I need to persist some data in a form even when validation fails. The code below (taken from the examples module) works - except for the first time the form is rendered and submitted (and the ...
0
votes
1
answer
16
views
Custom form module with file upload returns null value for file after submit
For a job interviewe task, I have to make a drupal module from scratch without the use of external modules. So far it's going okay, for someone who's new with Drupal, but I'm stuck at this point and I ...
1
vote
0
answers
24
views
Unable to display errors on AJAX form until next page load
I just started working with Drupal 10 and I'm having an issue with displaying form validation errors with an AJAX form submit. Everything works fine except the display of form validation errors if the ...
0
votes
0
answers
9
views
ECK form in modal
I am opening an eck form in a modal but when I save the new entity it redirects me to the newly created entity rather than close the modal.
I can't work out how to make it save the new entity and ...
-1
votes
1
answer
32
views
how to check only some options in a form with hook form alter
i am using hook form alter on drupal 9 and I want some of the select options to be checked . I can change the select options, but i can't make only some of them be checked
i tried setting the default ...
0
votes
1
answer
46
views
Passing a PHP value to JavaScript
I am trying to learn more about module development, so far I have a module that attaches Javascript to a certain content type. I am trying to have the data pull from a configuration form field.
...
2
votes
1
answer
22
views
File upload field prevents submit handlers from being called
I have a node form that I'm modifying a bit in a form alter hook. I added an additional submit handler:
$form['actions']['submit']['#submit'][] = static::class . '::redirectAfterCreate';
Clicking on ...
0
votes
0
answers
29
views
How to create a custom draggable table with depth but only having the deepest depth draggable
Here is what I achieved so far wich is pretty much the look and feel that I want except that it does not work as intended. (In my example, I want the end user to only be able to switch My node 1 and ...
0
votes
0
answers
17
views
How can I prevent managed_file form field type from reseting options set in the previous field using ajax?
When creating a form that has two selects where the second selects options rely on the first selects value then followed by a managed_file type field submitting the form resets the available options ...
0
votes
1
answer
27
views
How can I swap select options based on the response of a previous select?
I tried following the instructions to use '#ajax' to try and get these values to swap but nothing seems to be happening:
<?php
namespace Drupal\webform_test\Form;
use Drupal\Core\Form\FormBase;
...
0
votes
1
answer
31
views
How to change node edit's DELETE button to redirect to the node delete page instead of the JS popup?
We'd like to change the functionality of the DELETE button at the bottom of a node's edit page to redirect to the node's dedicated delete form instead of displaying the JS popup confirmation.
This is ...
0
votes
0
answers
48
views
hook_field_widget_form_alter() not retaining form field value when "Add another item" button is clicked
My hook_field_widget_form_alter() implementation looks as follows,
function mymodule_field_widget_form_alter() {
$field_definition = $context['items']->getFieldDefinition();
if ($...
0
votes
0
answers
17
views
Clear smart_date time input values after validation error
I have a smart_date field. During creation of a content with the smart_date field, when an error occurs on the time/date such as incorrect format, etc.. I want the values to be cleared.
Here is what I ...
0
votes
0
answers
20
views
Hierarchical select modules are showing excessive widgets during entity editing
For a few months now I noticed some difficulty editing entities using either 'simple hierarchical select' formatter or the 'client side hierarchical select' formatter. The widget splits up offering ...
0
votes
1
answer
66
views
Submitting an existing block or form in a modal doesn't work
I am trying to open either the simplenews subsription block or the corresponding form in a modal. I tried with both the form using the formBuilder service or the exising plugin-block and in both cases ...
0
votes
0
answers
12
views
Delete image from form after invalidated
I made a custom hook_alter_form to invalidate and delete a image if invalid.
php code in the .module file
<?php
/**
* Implements hook_form_alter() to add custom validation for image ratio.
*/
...
0
votes
0
answers
104
views
How add a cache context in a form_alter?
I'm on Drupal 10.2.x.
I'm writing a form_alter for a node add/edit form, where I am putting some extra markup data depending on terms of a vocabulary licenses.
function my_module_form_alter(&$form,...
0
votes
0
answers
62
views
File upload becomes empty after form submit for anonymous users
I've build a form in Drupal 9 with Form API.
When logged in as admin, all is working fine.
Selecting a file as anonymous works, and the validations are checked.
But when I submit the form, the ...
2
votes
1
answer
284
views
How override theme for a node add\edit form?
I'm on D10.2.x. My site uses Gin as back-end theme but also as fallback front-end, being decoupled and having to "front-end page" actually shown via Drupal.
I'd want to override the default ...
1
vote
0
answers
59
views
How to make a GET request to return Entity Registration form fields?
I am using Drupal as a decoupled CMS with Entity Registration module, and would like to get the Registration Type form fields to display on my SPA.
I have enabled the REST resource:
/entity/...
0
votes
0
answers
9
views
How can I manipulate an autocomplete text field exposed form filter to be a select list? [duplicate]
I have been trying to just use a form alter hook with code like this
if ($form['#id'] == 'views-exposed-form-my-form') {
$nids = \Drupal::entityQuery('node')
->accessCheck(FALSE)
-&...
0
votes
0
answers
55
views
What is the valid value for Webform element type in form-element.html.twig?
I'm currently attempting to rewrite the form-element.html.twig to incorporate custom CSS based on the label display and field type for Webform element output. While I've successfully identified ...
0
votes
0
answers
53
views
Inline Entity Form - how to set form field value in custom validate function
I have been struggling with this problem for few hours and I am unable to set form field values in a custom validate handler for an Inline Entity Form.
Inside _inline_entity_form_entity_form_alter ...
0
votes
0
answers
64
views
Change webform error status message
I'm working on making my webform on my site (D10) completely accessible. When I'm submitting my form empty I get a status message because I have two required fields. The message is:
2 errors have been ...
0
votes
0
answers
21
views
How to add dynamic dependency between two entity reference fields in content creation form?
I want to create a dependency between two Entity Reference (ER) fields, one towards content and the other towards vocabulary terms.
My first content type A has an ER field (A1) to a vocabulary (V1) ...
0
votes
1
answer
17
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",&...
1
vote
1
answer
46
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'
...
0
votes
0
answers
23
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=&...
0
votes
0
answers
60
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 "...
0
votes
0
answers
46
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 ...
1
vote
1
answer
92
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 ...
0
votes
1
answer
106
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 ...
0
votes
0
answers
34
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 ...
2
votes
0
answers
27
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 ...
0
votes
1
answer
50
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 ...
0
votes
0
answers
59
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'),
'#...
0
votes
1
answer
58
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 ...
0
votes
1
answer
113
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 ...
0
votes
1
answer
52
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' => '...
0
votes
1
answer
189
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, ...
0
votes
1
answer
320
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?
0
votes
0
answers
104
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 ...
-1
votes
2
answers
221
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
67
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 ...
1
vote
0
answers
159
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 ...
0
votes
1
answer
344
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 ...
0
votes
1
answer
120
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 ...
0
votes
1
answer
43
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 ...
0
votes
0
answers
36
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 ...