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
26 views

How to override views-exposed-form in a module?

I'm trying to override views-exposed-form. It works fine in a theme, but it's strange in a module. Eventually, it does find the template, but the form is available as {{ element }} and is missing the ...
commonpike's user avatar
0 votes
0 answers
308 views

Uncaught TypeError: Cannot read properties of undefined (reading 'messages') (forms AJAX POST)

Here I have created a custom module, which has one form in it...An ajax response is called when an Email is entered in form field and it will callback an HTML response. I have tested this code on my ...
kankari avinash's user avatar
1 vote
2 answers
42 views

How to pass node argument to a local task form?

Suppose I have a route for a local task like this: MODULE_NAME.node_options: path: '/node/{node}/options' defaults: _form: '\Drupal\MODULE_NAME\Form\NodeOptionsForm' _title: 'Options' ...
Anders's user avatar
  • 145
1 vote
1 answer
48 views

Local task for content node doesn't show up and raises 'Access denied'

After spending two days trying to figure this out, it's probably better to ask for help. I need to add a custom tab next to View Edit Delete Revisions Translate for content nodes (a local task, if I ...
Anders's user avatar
  • 145
1 vote
1 answer
70 views

How can I use EntityForm ::save() in a custom module? [closed]

How can i call public function ContactFormEditForm::save. My goal is refer to return value, do something like email, custom logged message, etc. Refer to api."Return value int Either SAVED_NEW or ...
user76445's user avatar
0 votes
0 answers
14 views

Adding a select box to a tableselect

I'm trying to use the technique outlined in this blog post: https://www.hexblot.com/blog/drupal-tableselect-fields to add a select box to a tableselect, but there are a couple of issues: The default ...
Lambic's user avatar
  • 708
0 votes
0 answers
48 views

How to add a confirmation form to an advanced configurable action?

So far I successfully implemented an advanced action (in a custom module) by extending ConfigurableActionBase and implementing ContainerFactoryPluginInterface. As expected, it appears listed in /admin/...
Anders's user avatar
  • 145
0 votes
0 answers
22 views

How can I set a node's nested (address field) value in a custom submit handler?

I need to clear any data from an address field's values (administrative area, etc.) In my custom submit hanlder for node form, I know I can use something like below for a standard field: <?php $...
quantumized's user avatar
  • 1,177
1 vote
0 answers
38 views

How to add the title with a sequence number to inline entity form?

I have an edit form of a custom entity that is passed to the controller: $form = $this->entityFormBuilder()->getForm($entity_quote, 'edit'); This custom entity has the reference field to another ...
antongordon25's user avatar
0 votes
0 answers
37 views

Webform get submission details after or during submission

How can I access the form data during or after submission? Am using Webform REST for the submission of forms, but I don't seem to be able to retrieve the form data. For now, I tried the following ...
Sidney Sousa's user avatar
0 votes
1 answer
52 views

Showing parts of ajax-enabled forms in Dialog and using submit buttons in Dialog to change the form?

I'd like to achieve the following (d10): In a form a list of custom drupal plugins will be displayed. Each of those plugins has a settings form array depending on its type that will be merged into the ...
witti's user avatar
  • 171
0 votes
0 answers
118 views

Using StreamedResponse for AJAX?

I am looking for a way with a Form API form in Drupal to have an #ajax event on a form field. When submitted, this calls a remote API. How can I stream the response out to the screen without the ...
Kevin's user avatar
  • 27.7k
0 votes
0 answers
22 views

My product variation is not shown on the entity form

I have many products coming from a migration. This is working for most of the products, but for some of them, the /commerce/modules/product/src/Plugin/Field/FieldWidget/SingleVariationWidget.php ...
lobafox's user avatar
  • 103
0 votes
1 answer
163 views

Form API: How to add arbitrary render element after specific field?

I've got an input field in an entity form which needs quite a bit of extra documentation. This documentation is long and needs computed, contextual information, so a simple field description or #...
Hudri's user avatar
  • 5,311
0 votes
1 answer
79 views

Need to pass $variable from validateForm back to form even if validation fails

It is a multipage Ajax form and I need to alter elements in a page based on form validation . This means, even if validation fails and the form stays on the same page, I need to visually alter that ...
Trudog's user avatar
  • 41
0 votes
2 answers
39 views

User form twig overwrite breaks after the submission doesn't have the current password

I am overwriting the user edit form using this code. function demetra_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { if ($form_id == 'user_form') { $form['...
pierostz's user avatar
  • 402
0 votes
0 answers
25 views

How to add "all" option to exposed filter?

I see this discussion for Drupal 7 but am trying to do something similar in Drupal 9. My view is called "content_display" and the display I am trying to affect is called ct_list (see ...
Patrick Man's user avatar
0 votes
0 answers
22 views

When "Use AJAX" is set to Yes on a View with Better Exposed Filters, the old search results are not cleared

Using Drupal 8, when AJAX is enabled on an exposed filter old search results aren't removed. I don't see any console errors but it seems that 'Use AJAX' isn't clearing the div before loading the next ...
user110190's user avatar
0 votes
0 answers
50 views

How to change markup of modal dialogs

A modal form is defined in openModalForm(), and the modal form is called by $form['open_modal']. public function openModalForm() { $response = new AjaxResponse(); // Get the modal form using the ...
shibasaki_stack's user avatar
0 votes
0 answers
75 views

Can I get form values in a controller after form has been submitted?

I'm working in D10 and what I have is a simple search form. It's two fields 'searchKey' (textfield) and 'showHidden' (checkbox). When the form is submitted a list of records is return and displayed in ...
RustedBucket's user avatar
0 votes
2 answers
164 views

Custom field Widget multiple values as a Table

Hello I created a custom field type and field widget with multiple values, one entity reference and two checkboxes. Everything's was working well, but to improve the usability of the fields, I would ...
NunesRodz's user avatar
0 votes
1 answer
43 views

how to alter entity reference field (taxonomies) field options in hook form alter

Can anyone please let me how to alter entity reference field (taxonomies) field options in hook form alter, Seems the below code doesn't work. /** * Implements hook_form_alter(). */ function ...
miststudent2011's user avatar
0 votes
1 answer
26 views

Unable to update node entity fields using custom form

There is a certain content type, in which there is a field to enter a node or taxonomy. I want to create a new node for that content type using a custom form and register the node or taxonomy in the ...
shibasaki_stack's user avatar
1 vote
1 answer
143 views

States on input type button broken since core update

I've updated my Drupal project from 9.5.3 to 9.5.7, but the submission button's #states property stopped working. $form['actions']['submit'] = [ '#type' => 'submit', '#value' => 'Accéder au ...
lobafox's user avatar
  • 103
0 votes
1 answer
87 views

Error when trying to retrieve a term with ajax

We are creating a custom form to edit a certain node. We do this above because there are some things that cannot be accomplished with the default form. I want to use AJAX to populate the fields of the ...
shibasaki_stack's user avatar
0 votes
1 answer
66 views

How to modify the timezone options list?

I have a date range field in a paragraph which is set to allow setting the timezone. Can someone suggest how I can alter the list of options used to select the TZ? For the user profile form a simple ...
liquidcms's user avatar
  • 1,224
0 votes
0 answers
586 views

How can I resolve the "Unique file URI" when using managed_file field in form API with a file name that already exists?

I am facing a strange issue with a managed_file field in my Drupal form API. Whenever I upload a file and save the form, and then come back again to upload another file with the same name, I get this ...
Zuhair's user avatar
  • 266
0 votes
1 answer
50 views

How to disable the option time_restriction that honeypot add to the forms

In the README file for the Honeypot module, it says: If you want to add honeypot to your own forms, or to any form through your own module's hook_form_alter's, you can simply place the following ...
Oskar Calvo's user avatar
0 votes
0 answers
81 views

Trying to filter the results of the entity autocomplete form element

Currently, I am working on a module that offers the function for users that belong to specific user roles to be able to write private messages to each other. In order for the sender to be able to add ...
Quetzcodecoatl's user avatar
0 votes
1 answer
252 views

When a custom form is displayed in a custom template, ajax does not work

What I want to do I want to display a custom form with a custom template and use ajax in it to change values in the form. Problem Custom template notation prevents ajax from working. I didn't change ...
shibasaki_stack's user avatar
1 vote
2 answers
122 views

When adding new nodes how can I pre-populate the body field with the body of another node?

I have a Drupal 9 website with number of nodes that I use as templates, I clone them to create nodes with the same body text. However, I want to make this process simpler by prepopulating the body ...
Yuri's user avatar
  • 618
0 votes
1 answer
288 views

Form field states with media fields that use media library widget and conditionally displaying visibility based on other media fields

I am trying to get some media fields to hide/show conditionally using $form fields #states API, based on other media fields (all the media fields are using the "Media Library" widget in form ...
sidgrafix's user avatar
0 votes
0 answers
24 views

Html5 tags and javascript stripped out form radio labels

On D7, I have the following simplified code function mymodule_multistep_form($form, &$form_state, $vars) { $mystatictext = get_my_static_text($vars); $options ='<div class="...
MMT's user avatar
  • 41
0 votes
0 answers
46 views

How to set media field mappings to autofill the target fields when uploading the file instead of saving to those files when saving the media entity

I am using the document media type for pdfs. I am also utilizing the field mappings for: Name MIME Type File size and I will be adding a field mapping for the pdfs subject as well using a Media ...
GradoniusTheWise's user avatar
1 vote
1 answer
150 views

Storing temporary data in a form AJAX callback

I have a form submit button that when clicked fires an AJAX callback. $form['actions']['submit'] = [ '#type' => 'submit', '#value' => $this->t('Title...'), '#ajax' => [ 'callback'...
Kevin's user avatar
  • 27.7k
0 votes
1 answer
112 views

Check in buildForm method of custom form class if the form was submitted

I have created a large form with a class extending FormBase. Many of the elements rendered within the form are only necessary for the user to see - there are not so many really relevant fields in the ...
Tobias Krause's user avatar
0 votes
1 answer
59 views

Block Configuration Form Returning Unexpected Value

I'm trying to build a block configuration form. Here's my blockForm code: public function blockForm($form, FormStateInterface $form_state) { $form['resolve_ip_addresses'] = [ '#type' => ...
Scott Hollenbeck's user avatar
1 vote
0 answers
23 views

Focus Returns to Field With AJAX Callback [duplicate]

I am attempting to complete several AJAX commands based on the value of a field in a node/add form. The commands themselves work. However,when a user is filling out the form the cursor (focus) keeps ...
Drupal Learner's user avatar
-1 votes
1 answer
79 views

How to remove author field from the 'advanced' field group on the node edit form

I've got several node edit forms that, in most themes, display the 'advanced' group in a sidebar. I have other plans for the sidebar, though, so I don't want that behavior. I edited some twig and css ...
aharown07's user avatar
  • 362
1 vote
1 answer
203 views

How to check for content type in hook_form_alter

I see from the api and various posts that I can identify a specific form to change using hook_form_alter, like this: hook_form_FORM_ID_alter() From experience, I know this can be done in the .theme ...
aharown07's user avatar
  • 362
0 votes
0 answers
74 views

Custom widget with entity reference and another field - not saving

I'm trying to create a custom field for my entity (entity A). It will hold custom entity reference, let's say entity B, with another field associated (integer). I want to create associations entity A -...
drupaltest's user avatar
0 votes
0 answers
28 views

Form tries to process submit field as entity property

I want to create a simple admin CRUD form. I am using the default form. class TestForm extends EntityForm { public function form(array $form, FormStateInterface $form_state) { $entity = $this-&...
guest's user avatar
  • 1
0 votes
0 answers
27 views

Trying to create a cell when using tables in forms

In one of my custom Drupal modules I'm trying to crate a form that also contains a table. One of the table sections looks like the following: $form['consumption_' . $week]['mood']['title'] = array( '...
Quetzcodecoatl's user avatar
0 votes
1 answer
113 views

Run custom php code or file in drupal content type form submission

I have this drupal site, there is a candidate registration page where anyone can fill the details (name, gender, address, mobile no etc) and submits and a success node page is displayed with all ...
user3099225's user avatar
0 votes
1 answer
49 views

Dynamically generate Form API select list of routes to page displays of a known View

Given a known View, how would one dynamically generate a Form API select list of the routes to its Page Displays? In my case, I have a Search API View (view.search) with a default site-wide search ...
hotwebmatter's user avatar
  • 2,102
0 votes
1 answer
94 views

Why does this code to create a dependent dropdown not work?

I am trying to implement the dependent dropdown option in Drupal 7 from this URL http://w3shaman.com/article/creating-ajax-dropdown-drupal-7. When changing the first dropdown value, it is showing the ...
Rajat Bhardwaj's user avatar
1 vote
1 answer
139 views

Form builder not getting checkbox values

I cannot determine why the form state seems to fail to get the values of the checkboxes on a form I'm building. In my buildForm(), after submission, I am returning a result set. Each result that is ...
Travis's user avatar
  • 457
0 votes
0 answers
23 views

Twig template for field component of specific form [duplicate]

I'm using template hints to attempt to theme a specific part of a single form. I have a custom template for a views block (block--views-exposed-filter-block--search-custom-page-1.html.twig), but is it ...
Sam's user avatar
  • 585
0 votes
1 answer
61 views

AJAX on Form Details

I have a lot of API calls in a form, so in order to not call everything on load, I only want to load it when the user opens the details element. But I am having trouble adding #ajax to the element. I ...
NicklasF's user avatar
  • 289
0 votes
1 answer
258 views

Dynamicaly add ajax form item and add event on checkbox

I've added an ajax callback to my form to add some data on it : $form['add'] = [ '#type' => 'button', '#value' => t('add'), '#ajax' => [ 'callback' => [$this, '...
lobafox's user avatar
  • 103