Questions tagged [forms]
Use it for questions about the Form API. Don't use it for entity or entity field forms.
6,767
questions
0
votes
1
answer
91
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 ...
0
votes
1
answer
79
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->...
0
votes
1
answer
36
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" => "...
0
votes
0
answers
18
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
- ...
1
vote
0
answers
217
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 ...
0
votes
1
answer
86
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 ...
-2
votes
1
answer
43
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:
...
0
votes
0
answers
33
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 ...
2
votes
1
answer
174
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:
/**
* ...
1
vote
1
answer
221
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(...
0
votes
0
answers
39
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 ...
0
votes
1
answer
23
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 ...
0
votes
0
answers
14
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 ...
0
votes
1
answer
444
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 ...
1
vote
1
answer
307
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',
'#...
0
votes
1
answer
229
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:...
0
votes
0
answers
43
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 ...
1
vote
1
answer
72
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' =&...
0
votes
1
answer
56
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 ...
0
votes
1
answer
198
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 ...
0
votes
0
answers
31
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 ...
0
votes
0
answers
160
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 ...
0
votes
1
answer
114
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 ...
2
votes
1
answer
61
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 (...
0
votes
1
answer
242
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 ...
1
vote
1
answer
88
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(...
1
vote
1
answer
132
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 ...
0
votes
1
answer
73
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 ...
0
votes
2
answers
98
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 ...
1
vote
1
answer
534
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 ...
0
votes
0
answers
217
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 ...
-3
votes
1
answer
209
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 ...
0
votes
2
answers
81
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 ...
0
votes
1
answer
154
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 ...
0
votes
0
answers
76
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 ...
0
votes
1
answer
50
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 {
...
0
votes
0
answers
217
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 ...
1
vote
1
answer
387
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 ...
1
vote
1
answer
265
views
Get the node title field value in the form_state
Drupal version 9.3.9.
This is a process of Ajax callback, where the value of the title field is required. In the form node add, the title is displayed. It seems that the form_state does not apply to ...
1
vote
2
answers
366
views
How can I change the title of the node/add page of a specific content type?
I want to change the title of the node/add page of a specific content type. Twig debug only shows me file names that would also change the titles of other content types. There was a module for this in ...
0
votes
0
answers
57
views
Creating link option in form and modifying it's url in form alter hook
I'm searching to modify a node add form, so far i added a personal field "link" to display as a button to add another node type if the user wants to, that link has this code in ...
0
votes
0
answers
55
views
How can I standardize the query from exposed form input?
I apologize in advance if the title for this post is misleading, my intention is to use exposed form input from a form in a block display (not on the view page) to build a query on a page display for ...
-2
votes
1
answer
38
views
How to implement a social media feed [closed]
I am creating a social media app and basically need a page that is a form with fields for the users to fill out and add a new post to their feed (form connects to the feed).
More detail:
The form ...
0
votes
1
answer
64
views
How to add a boolen attribute to a form?
I am trying to add the boolean attribute "novalidate" to all my forms.
I have tried numerous approaches in my theme_preprocess_form function but no luck. I see in some preprocess functions, $...
0
votes
1
answer
84
views
Render Submitted Fields of a Form to Email with Title + Value
I have a quite complex form based on \Drupal\Core\Form\FormBase with many (partially nested) fields and want to send the full contents in an email on submit.
Currently I have
public function ...
-2
votes
1
answer
494
views
How to check and disable one of the checkboxes in a form?
I found this snippet in the code for a form ($roles is an array of roles).
$form['config_options']['roles'] = [
'#type' => 'checkboxes',
'#options' => $roles,
];
// Check and disable the '...
-2
votes
1
answer
14
views
How can I loop on checkboxes to hide all using mlid: from the datatable?
function ts_core_form_menu_overview_form_alter (&$form, &$form_state, $form_id) {
$form['mlid:11242']['hidden']['#type'] = 'hidden';
$form['mlid:11246']['hidden']['#type'] = 'hidden';
$...
0
votes
0
answers
17
views
Is there a way to improve the entity autoselect especially for multiple entities?
The entity autoselect is a strange UI element that lets you type something, if you select a match, it puts that text in. If you want to include two items you need , to separate them.
What if there ...
0
votes
0
answers
35
views
How to clear selected values from multiple select field
I have a form with a multiple select field where a user can select several values in it
$form['export_type_section']['export_type'] = array(
'#title' => t('Export types'),
'#type' => '...
0
votes
1
answer
25
views
FormAPI - Values of AJAX added fields missing from values array on submission
I'm using the Form API to create a form where I have multiple instances of a fieldset. Each fieldset contains the same fields, one for storing an email address and another for another bit of ...