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

entity_form how to programmatically add references and update the form visually (entity_browser)

I´m having an fieldable entity with a reference field to paragraphs field_paragraphs and a paragraph_type with a reference field to content_type event field_events. What i am trying in the entity form ...
0
votes
0answers
17 views

How to retrieve #tree values inside a multiple containers?

I am using Drupal 8 and I am creating multiple forms that are made of a #tree hierarchy. I am retrieving the value of the "first name" from the #tree using the below code and it doesn't get ...
0
votes
0answers
8 views

Errors when passing in URL Parameters for Views exposed filters that are selection lists

I have a Content View that has some a few exposed filters and I added a filter identifier to them so that I can pass filters in through via URL Parameters. This works as expected for some basic ...
0
votes
0answers
13 views

How to return an XLS file to download on form submit

I am trying to create an XLS file and send it to the browser on a form submit but I cannot figure out how to do it. I am using XLS Serialization module. With this module I successfully created some ...
0
votes
2answers
30 views

How to retrieve #tree values inside a form?

I am new at Drupal 8 and I am creating a module that has a #tree form. I chose #tree form to create multiple forms which has the same textfields and button. I came across one document in drupal about #...
1
vote
1answer
36 views

Render responsive image inside form fields programmatically

I am trying to figure out how to render a responsive image programmatically inside a form field. I am doing maintenance in a code on my current job, and sometimes there are form fields using the '#...
-3
votes
2answers
32 views

How to fill a form field of type fieldset with values from an array

How can I fill a formfield type fieldset with more than one markup value from an array? foreach ($drugis_postgis_connection->tableNames() as $table) { $form['tables'] = [ '#type' => '...
0
votes
1answer
36 views

How can I filter the path aliases by node id?

On this page admin/config/search/path, we can only filter the results by URL alias. I want to filter the results by node id as well? How can I do that? It is not possible with form alter. As the ...
0
votes
1answer
65 views

Throw error for required field in hook_form_alter?

I have a node type that can be created by authenticated users. In the node create form, I added a terms-of-service checkbox via a form hook like so: function themename_form_alter(&$form, &$...
0
votes
0answers
33 views

How to create similar multiple forms using a button?

I am using Drupal 9. I am creating a module that has a form with a button that will re-create another form similar to the first one. These is my code. public function buildForm(array $form, ...
1
vote
0answers
26 views

Register form block into modal

I want to display the register form in a modal. For that, I created a custom plugin block which returns the rendering of the form register. /** * {@inheritdoc} */ public function build() { $...
0
votes
0answers
10 views

Can't open url link or images in CKEditor on a modal form

I have created a custom form with a text field that uses ckeditor. I open this form in a modal window. It works good, but if you try to use url link button or image button, because they are opened in ...
-2
votes
1answer
40 views

How to open a form in modal from controller while redirect

I can open a form in modal when click on a link (and there are lot of examples in the net as well). What I like to do: When some one go to a url in browser or redirect to a url, it will open a dialog/...
3
votes
1answer
44 views

AJAX Form using a sub-class of ContentEntityForm fires/invokes/calls the WidgetBase::massageFormValues() twice

I'm using a AJAX form. This form I build from a sub-class of ContentEntityForm. The Entity edited by this form has a field MyField. To bring all the field values in a appropriate structure I'm using ...
-3
votes
1answer
50 views

Open new tab with external link using an image button

I am making a custom module with a form that has an image button. The image button will open the external link with the value of a textfield inside the form. I have searched any possible solution in ...
0
votes
0answers
40 views

Render fields and results of a custom form in two separated regions

I have a custom form (created programmatically). I want to keep the AJAX submission mode. I would like to render the fields of the form in a region SIDEBAR and then the results in the region CONTENT. ...
-2
votes
2answers
39 views

Can I use two different forms in one module?

I'm new to Drupal 8 and I was wondering if I can use two forms which are inside the Form folder(mymodule/src/Form/). The name of my forms are FormOne.php and FormTwo.php. I can only display and use ...
0
votes
0answers
14 views

How set violation to postal_code field on Address Fields

Address field is collection of other fields that one of them is postal_code. I wrote a custom validation constraint. It is applied and working. but the error message is showing for all fields of ...
0
votes
0answers
31 views

How to inject/append child element to a radios element and give it an AJAX callback?

How can I add independent child element to a radios element in a form? The radio elements are created by the following code. $form['orderinfo']['billshipaddresses']['billingaddresses'] = [ '#type' =&...
0
votes
1answer
38 views

Actions form array overriding to set HTML id attribute

I extend the EntityForm class and I try to override a submission button, to set its HTML ID attribute (try #1). Since it doesn't work, I tried to wrap the button in a wrapper <div>. I tried to ...
0
votes
0answers
27 views

How to see if ajax has been added to a simple node form?

This very simple #ajax customisation to a node form is not working. How can I tell whether the callback has been added? I want to calculate a field if the first field is changed. function ...
0
votes
1answer
79 views

Render custom field from user registration form

I'm trying to render a custom field that shows up on the user registration form on a separate new form that creates users of a particular role with specific permissions. I have everything working ...
0
votes
0answers
47 views

Ajax form ReplaceCommand functionality breaks after first fire

I Have a form on a page which updates a single field of a Node. The form uses ajax to update the field and returns the newly saved entity and replaces the current HTML so the new field is showing up ...
-2
votes
1answer
29 views

Unable to create a custom form tableselect [closed]

/** * An example controller. */ class GenerateCertificateTable extends ControllerBase { /** * Returns a render-able array for a test page. */ public ...
0
votes
0answers
14 views

Can I display how many questions left in a form from the Webform module?

Is there a non-code way to show how many questions are left in a multipage webform module? For 508 reasons we (at work) use multiple pages for forms. Some pages have 2 questions while other have have ...
0
votes
0answers
21 views

The form argument Drupal\terminal\Form\TerminalCliForm is not a valid form

I've read through other questions regarding the same error message. They all seem to end up being due to typos or the file path. I don't believe that is the case here, but we'll see. I have a working ...
0
votes
0answers
37 views

cURL request causing form validation error

I'm working on a cURL request when a user submits an existing form to send some data to an outside service. I've added this function with this line: $form['actions'][$action]['#submit'][] = '...
5
votes
1answer
106 views

How to make a checkbox read-only/disabled from list of user entity references

In my Content type, I add a field Reference: User with unlimited values, Reference method from a view of user managers, and widget checkboxes. Basically when a user manager edit the node, he can only ...
0
votes
0answers
26 views

How do I add a media item with a custom form? [duplicate]

I have a custom form that currently uses a managed file field and then stores the value in config. However, if there is ever an issue, the user must remove and upload a new file. I would like them ...
1
vote
0answers
34 views

Send an AJAX response and rebuild a form in a single AJAX callback

I need to execute multiple AJAXCommands and rebuild form in one AJAXCallback function, but the documentation says the AJAXCallback function should return AjaxResponse OR FormElement. Using ...
2
votes
2answers
58 views

How to set a validation constraint for base fields like the taxonomy term name?

I'm having trouble setting a validation constraint on the name of the taxonomy term. function MYMODULE_entity_bundle_field_info_alter(&$fields, $entity_type, $bundle) { if ($entity_type->id() ...
5
votes
2answers
62 views

How to make taxonomy term names unique per user?

I have a taxonomy vocabulary, Groups. Requirements Different users can create groups with the same name. (User A can make an apples group, and User B can also make an apples group.) The same user ...
1
vote
1answer
18 views

How can I tell, in hook_form_alter(), if a node form is for the node in its default language or a translation?

I'm implementing hook_form_BASE_FORM_ID_alter() in a custom module. I'd like to know if my form is for the node in its default language, or a translation of that original node.
1
vote
1answer
55 views

How do I set the default value for a user entity reference field in hook_form_alter()?

I tried the following code, but it doesn't work. $form['field_name']['widget'][0]['target_id']['#default_value'] = \Drupal\user\Entity\User::load(\Drupal::currentUser()->id());
0
votes
1answer
23 views

Using radio FormElement in a drupal 8 ListBuilder

I made a custom configuration entity, and I'm trying to set up radio buttons in the listBuilder. This is done in the core module language without any problems, but when I try to do the same trick with ...
2
votes
0answers
27 views

How do I add a template suggestion for form input fields that have containers?

I've been able to successfully add the parent form ID to all form elements, based on these two questions: How can we find the id of the parent form in preprocess_HOOK() or HOOK_alter() theme functions?...
0
votes
1answer
53 views

hook_forms() not working

I'm trying to add a button to all node forms via callback in hook_forms. I get a similar error. Can someone help. Warning: call_user_func_array() expects parameter 1 to be a valid callback, class '...
0
votes
0answers
40 views

How to close a modal with a submit form and implement a CloseModalDialogCommand?

I saw this issue here, but I wanted to post this question as the answers seem incomplete and the question is not specific to closing a modal with a submit form. In my .module file, I am using a ...
0
votes
0answers
13 views

Admin custom configuration form add more field issue

I have created below admin custom configuration form by taking a reference of below examples: https://git.drupalcode.org/project/examples/-/blob/8.x-1.x/form_api_example/src/Form/AjaxAddMore.php How ...
0
votes
0answers
24 views

Form API States required don't seem to work on a custom form with ajax [duplicate]

I can't get form states required to work on an ajax submitted form. Here is some example code. It is taken from the examples module and slightly modified to illustrate the problem. /** * {@...
0
votes
0answers
40 views

How to get the previous dynamic value generated by autocomplete?

I added an AJAX "Add more" button in a form. After the autocomplete event, I replace some text. It works only the first time; the other times, the first value is removed. namespace Drupal\...
1
vote
1answer
15 views

Add rows to form tableselect with AJAX

I would like to: 1.) Add rows to a tableselect form element when a user clicks on a button. 2.) See which rows are selected when a user clicks on another button. Part one is complete (I've only ...
0
votes
1answer
21 views

setError or setRebuilld methods breaks validation form

<?php namespace Drupal\my_custom_module\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; /** * Class DefaultForm. */ class DefaultForm extends FormBase { /** ...
0
votes
1answer
44 views

Pass a value via URL to a node edit form and use it to redirect after saving the node

I have a node that includes a series of embedded views. When displaying, I have to pass a value via URL arguments (http://example.org/node/x?id=y), so that the views can get the appropriate ...
1
vote
1answer
49 views

How to get access to a $form in hook_entity_view_display_alter?

In Drupal 9, I added a views_add_to_cart_form view mode to be able to render a product entity with only the Variations field formatted as add to cart form being displayed. That all works as expected, ...
1
vote
1answer
50 views

How to add a secondary Ajax submit to a regular node form?

I'm trying to add an Ajax submit to a regular node edit form (Drupal 9). I'm using Field Groups so that there's a series of tabs, and I've added a pair of "buttons" (Right now they're just ...
2
votes
2answers
71 views

What is best practice for passing routing parameters?

In submitForm() I want to redirect to a controller and pass the form values. The form values are all arrays, btw. Here is submitForm. public function submitForm(array &$form, FormStateInterface $...
-1
votes
1answer
34 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'] = [ '...
1
vote
1answer
58 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
38 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 ...

1
2 3 4 5
133