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
1answer
21 views

Why do I get “An invalid selection has been identified.” from the form my code creates?

I am using the following code for a form. public function buildForm(array $form, FormStateInterface $form_state) { $region_options = static::getFirstDropdownOptions(); $form['vvv_region'] = [ '...
0
votes
0answers
56 views

setError() breaks validation and causes an “Allowed memory size of xxx bytes exhausted” error

I'm creating a simple form with the following code. class UserRegisterForm extends FormBase { /** * {@inheritdoc} */ public function getFormId() { return 'user_register_form'; ...
1
vote
1answer
49 views

How to prevent theme change caused by $rendererService->renderPlain()

I'm trying to re-use the output from a heavily customized field formatter as <select><option> text in a Webform. I managed to re-use field display, but it has the side-effect of switching ...
0
votes
0answers
28 views

How can I select multiple rows from a table and let the submission handler know which rows have been selected?

In a custom module, I have a form showing a table with multiple rows, as in the screenshot. Once users select one or more rows, and they click on the Delete button, rows in the database should be ...
0
votes
0answers
23 views

Prepopulate fields from json

I am looking to prepopulate a page full of fields (not webform) from a json file. There are a lot of fields on the page and some of them contain a lot of info, so it doesnt appear that it is practical ...
1
vote
1answer
31 views

How do I force the pager to update?

I have a custom form built with the Form API. The general flow is: Build and display form Get user input Rebuild and form query based on user input with added $query = $query ->extend('Drupal\\...
1
vote
1answer
32 views

How to add language prefix to form action?

We have a multi lingual site that default is "en". Sometimes editors are creating content in another language like "de" and than translate it to "en". My problem is that ...
2
votes
1answer
37 views

How to hide a form element when a datetime widget is filled using #states

The following code is working well to hide a button when a textfield is filled, but it is not working when a datetime widget is encoded: $form['my_button'] = [ '#type' => 'container', 'submit' =...
0
votes
0answers
30 views

How to save a ajaxified value in a form

I add a ajax callback to a select field $form['field_equipe_membre']['widget']['#ajax'] = array( 'callback' => 'ajax_desactive_unites_field_callback', 'event' => 'change', 'method' => 'html', ...
-2
votes
1answer
24 views

How to add an external link inside form actions?

I want to programmatically add an external link next to my submit button in a form that I have created.
1
vote
0answers
33 views

How to filter entity_autocomplete results by content type and a field

I am trying to implement an entity autocomplete field in a form where the autocomplete entities are filtered by content type and a certain field of that content type. I know I can filter the ...
-2
votes
0answers
35 views

Create a search filter on my custom module form

The custom form is calling google apps and developers API's to display some apps and developer details like in the picture attached. I want to be able to apply search filter on this form for app name, ...
1
vote
1answer
37 views

Custom form password validation / strength enforcement

I have a custom form that would create user. The form is rendered with Form API and is using PasswordConfirm element, but it doesn't seem to validate the password against the default password rules (e....
1
vote
1answer
89 views

buildForm: how differentiate between page reload and ajax callback?

I'm building a custom form in Drupal 9, which has some ajax callbacks. During the buildForm I need to load some extra data via a rest call to an external service, which then I put inside a ...
0
votes
0answers
38 views

How can I add a constraint to a custom form element?

I am trying to create a simple form with a single field. I have a custom constraint created for the validation of a custom field. I would like to add the same constraint to the form element, instead ...
1
vote
2answers
26 views

How do I automatically fill the subject in the contact forms?

I created 2 types of contact form. I disabled Subject in Manage form. I want the fake Subject field not to be displayed in the contact form, and I want it to be filled in automatically. How do I ...
1
vote
0answers
41 views

Form with ajax and javascript problem

I re-create the question with more accurate data (Original question Form with ajax and javascript problem). I have a button in my form that generates a fieldset via ajax. When I try to track this ...
0
votes
0answers
41 views

Send hook preprocess_views_view results to custom form or services

I am developing a feature that allows anonymous users to receive by email the result of a facets + searchAPI. Facets and Search API work perfectly. The custom module that allows to send an email too. ...
0
votes
0answers
12 views

Is it possible to make a managed_file field drag and drop?

I have a single-value managed_file field on a custom form in Drupal 8 that I need to make drag and drop. I don't want to use another field type like dropzonejs because I have a complete complex ...
1
vote
1answer
60 views

What is the new methodology for Form Pre-Render in order to utilize TrustedCallbackInterface

We are upgrading our sites one at a time from Drupal 8 to Drupal 9 and there is one line of code in our custom theme that is the last of our problems. We get the following error on View that uses an ...
-1
votes
1answer
18 views

How do I add link to Edit and Delete in a column in a view table item list?

I've trying to add a link to Edit and Delete column to perform desirable actions. I need help in implementing it. I've tried several suggested methods on the internet, but none did the job for me. ...
0
votes
0answers
73 views

Sharing Heavy Operations between multiple Page Elements

I have a page with two separate page elements. One is a table-select form that shows an extensive list of content data. The other page element is a block that shows a summary of that same content. ...
-2
votes
1answer
25 views

Adding select list to tableselect output

I'm trying to add a select-list to some table output but the markup is rendering as text. $header = [ 'col1' => t('COL1'), 'col2' => t('COL2'), ]; $rows = [ 1 => [ 'col1' => '...
-2
votes
1answer
44 views

Why an exception is raised when I insert a token as a value of an html src attribute

How to raise the exception: In any text_area field using ckeditor, insert the following code <img src="[node:my_custom_token]"> and save the form. You will get the following error: (...
0
votes
0answers
21 views

save a selection from an ajaxified field

I successfully update a field from ajax. Its declaration is the following : $form['field_unite_de_recherche']['widget']['#ajax'] = array( 'callback' => 'ajax_equipes_from_unites_callback', '...
0
votes
0answers
21 views

rebuild a form with ajax (solved)

In a hook, I use ajax on a form field, designed with drupal user interface. It is declared as this : $form['field_unite_de_recherche']['widget']['#ajax'] = array( 'callback' => '...
2
votes
1answer
41 views

Validation on custom entity edit form

I have a custom entity where, instead of using the usual way of specifying edit form options with setDisplayOptions('form' and relying on ContentEntityForm to create my edit form for me, I have to ...
0
votes
0answers
21 views

Managed_file with table of uploaded files

Adding a file field to a custom node type results in a nice UI with a table appearing for all uploaded files, with a Remove button for each. But simply adding a managed_file to our own forms, eg: $...
2
votes
1answer
46 views

How can I provide my own replacement patterns to be used in config form?

I want to give a configuration form where user can configuration text on a widget, like the description and button label, however I want to provide a replacement pattern to be used, like {{count}} so ...
0
votes
1answer
30 views

How to set default value on Select2 Autocomplete via hook_alter

What's the best way to set a default value to a Select2 autocomplete field widget on form load (I'm using a reference view to populate options). I've tried a ton of different variations from within ...
2
votes
1answer
57 views

CSRF token is not varying in Ajax callback while submitting form

I have a form with ajax callback as following , on each submit token is not varying , it remains constant for all submit . wall.routing.yml wall.commentform: path: '/commentform' defaults: ...
0
votes
1answer
43 views

How to create a dblog record from a views exposed form submission

I am trying to create a log record of searches made though my Search API View exposed form block in Drupal 9. For some reason on a brand new search I get 2 duplicates (3 total entries), and it seems ...
0
votes
1answer
27 views

Proper way to get input field value with AJAX

I want to do some calculations in node edit form vith ajax. Form fields is created via UI, so i need to drill into field array to get value(s). Maximum result what i have is replacing target field ...
2
votes
1answer
50 views

How do I stop Form Builder/API from filtering certain HTML tags from #prefix and #suffix on fields?

Summary: Drupal seems to be stripping certain html tags from the #suffix of Form API created fields and I can't figure out how to stop it. Environment: Working in Drupal 8.9.13 with a minimum of ...
0
votes
1answer
23 views

How can I change the label on the “Add media” button in media field widget?

I would like to change the label on the button named "Add media" on the media field widget. For instance to write "Add image" or "Add document". How can I change it?
1
vote
1answer
24 views

How can I add a pattern attribute to a phone field?

I am trying add pattern attribute to phone field of drupal's core feedback form. I am trying to do like this in mytheme.theme function mytheme_form_alter(array &$form, FormStateInterface $...
0
votes
0answers
27 views

Redirect to another action in submit function in a multiple button form

I wanted to alter a form to add a new button. I implemented the hook_form_alter() and this works fine. function mymodule_form_alter(&$form, FormStateInterface $form_state, $form_id){ $confirm = ...
-1
votes
1answer
33 views

Add custom form to content type (Basic Page or any) using custom extesnion

I am new to Drupal. Actually, I have to add a custom form to the content type and it will be visible to the frontend user where they can submit their response. So I have created the form and save the ...
0
votes
1answer
21 views

How do I pass a context filter to a block loaded by ajax?

There is a block created in views that displays the values of the taxonomy term fields. This block should be loaded when selecting a term from the select field in a custom form. Accordingly, the block ...
0
votes
1answer
40 views

Why ConfigFormBase does not goes through custom construct() when using managed_file?

First I want to state that this is a question. My Form is working, but I had, strangely, to add clauses for the case when my CustomForm extending ConfigFormBase did not goes as expected throught the ...
0
votes
0answers
27 views

Loading form by Ajax and Submit by Ajax

This question is asked few times but I am still lost on my solution. I did check this but couldn't make my code work. My my_module.routing.yml entity.node.my_module_form.node: path: '/contribute/{...
0
votes
0answers
46 views

How can I invoke a custom submission handler for a view field?

I would like to display a button for each content displayed in a view. In a custom module, I have added a custom submission handler to the edit form (hook_form_FORM_ID_alter()) and defined the action ...
0
votes
0answers
25 views

how to order grouped fields in the sidebar on a node form

On my old Drupal 7 site, I was able to group a set of fields and display them as a tab in the sidebar. I'm moving it to Drupal 8 and using the adminimal theme. I created groups and am using the ...
-1
votes
1answer
25 views

Get value of a checkbox that is an element in a #rows array

I am building a table with checkboxes without using tableselect for various reasons, but am trying to retrieve the checkbox value similar to how tableselect does. Tableselect will populate the values ...
0
votes
1answer
31 views

Add a link to a tableselect row

I'm interested in adding a link in a tableselect form row. Utilizing the #options key I can only add columns with strings. I am able to add form elements in the #options array similar to the #rows ...
2
votes
0answers
99 views

Multiple dependent form fields

I'm building a form following the ajax examples module, specifically the dependent dropdown form. I've tried the same approach as the example, calling a static function to retrieve the options for the ...
2
votes
0answers
21 views

Entity Validation API not invoked on saving the taxonomy overview form – misunderstanding or a bug?

I have a Constraint and ContraintValidator to validate a field of taxonomy terms. Its a hierarchical taxonomy called channel with a field field_product. It's required that a channel has the same ...
0
votes
1answer
40 views

When doing a page preprocess, how do you know if the page is a form?

When doing a preprocess on a page (I need to conditionally change something at the page template level) is there a way to tell if the page is going to render a form? The xdebug output didn't show any ...
-2
votes
1answer
27 views

Form APi Could not parse property path Unexpected token

Using Drupal 9.1.4 symfony/property-access I think is on 5.2.0 [that's the last version mentioned in the changelog] I have a custom built form with some date and number fields, for example: $form['...
2
votes
2answers
54 views

How to create a new parent section on the Configuration page?

When one navigates to Manage » Configuration, the page is divided into sections which (in the "Seven" theme at least) shows up in individual boxes. These sections have headings like "...

1
2 3 4 5
133