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

How do I pass values from a function to another while using form submission batch?

I am working on a custom module which processes a JSON file and downloads images from URLs in the JSON object, creates a new file entity, replaces the image URL in the JSON file with the file ID, and ...
0
votes
0answers
24 views

Why is wrong ajax callback function called?

I have two buttons $form['button_1'] = [ '#type' => 'button', '#value' => false, '#ajax' => [ 'callback' => '::ajax_submit_1', 'wrapper' => 'wrapper_1', ], '#...
0
votes
1answer
23 views

How to disable form button on ajax callback?

I have a button with ajax callback and I want to disable it on button click without page reload. Preferably inside ajax_function but it's not obligatory. $form['my_button'] = [ '#type' => '...
0
votes
0answers
26 views

setErrorByName() not highlighting multi-select fields

I have the following HTML code, generated by drupal <div class="multiselect-selected"> <select multiple="multiple" name="field_test_ins[]" data-drupal-selector="edit-field-test-ins" aria-...
1
vote
1answer
20 views

Custom Validator on Custom Form

I see all kinds of examples of how to add a custom validator to an "existing form." Which means, you would use hook_form_alter. I want to add one in the code for my custom form. I'm adding this in ...
-1
votes
0answers
12 views

Theme suggestion for commerce-cart-form input--submit buttons [duplicate]

I have a Drupal Commerce cart view (overview of the cart). In the form 3 buttons are rendered. delete-order-item button update list button checkout button I want to create 3 specific theme ...
1
vote
1answer
42 views

Why ajax button calls submitForm?

I have no problems with using Ajax in every form element other then button. When I'm clicking this button '#type' => 'submit', '#ajax' => [ 'callback' => '::ajax_function', '...
0
votes
0answers
25 views

How can I override the form-element-label.html.twig template?

In a view, I have checkboxes displayed using the better-exposed filter. Ajax setting is true. Currently, there is no template suggestion for overriding form-element-label.html.twig. Somehow by adding ...
1
vote
1answer
28 views

Table in custom form + empty values in form_state

In a custom form I created a table element: // Table results. $form['table'] = [ '#type' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => ['id' =&...
0
votes
0answers
28 views

How do I allow authenticated users to remove their resume file from their user profile? [on hold]

I am using Drupal 7.67 instance with CiviCRM integrated. Authenticated Users on my website are able to upload Resume to their user profile. However, they aren't able to remove the resume or replace ...
0
votes
2answers
26 views

Hide one form element until another is selected

Is there any way to disable the field 'model_article_nr' until 'model' is selected this is what i have and as it is now i can select 'model_article_nr' before i have choosen a model which leads to ...
1
vote
1answer
30 views

How to disable htmlspecialchars in custom module form table?

I'm making a table form $form['table'] = [ '#type' => 'tableselect', '#header' => $header, '#options' => $this->getOutput(), '#empty' => t('No vehicles found'), ]; In ...
0
votes
1answer
30 views

How to get the form field label of a multi-value field

In hook_form_user_form_alter I need to get the title of each field. When I dump a normal (single-value) field #title is an array value, like this: array (size=13) '#title' => string 'Name' (...
0
votes
2answers
48 views

Ajax validation only works when I am logged in as an administrator

I have created a custom contact form and I have set up an ajax inline validation. My form works very well. But Ajax validation only works when I am connected. When I am not logged in as an ...
-1
votes
0answers
12 views

Ajax_command_replace a form, old form errors persists

I have a form made with 3 checkbox and one of them have a value that change in function of precedent forms choices. So I use the ajax_command_replace command to refresh my form like this : $...
0
votes
1answer
38 views

Add separate div after a form

All I want to do is add a new <div>, ideally just after a <form> element. I have a self-written module that generates a payment form, using some routing, like this: mymodule.applications....
-2
votes
1answer
29 views

How can I create a new Paragraph item programmatically in an Ajax form handler?

I need to add Paragraph fields programmatically to an entity in an AJAX handler. This is my AJAX callback and how it's added: function mymodule_form_alter(&$form, \Drupal\Core\Form\...
0
votes
0answers
18 views

Field collection required field is not working

We have a set of field collection with required and non-required fields. The actual requirement is the form should be submitted only if all the required fields were filled. But it fails to work on ...
0
votes
0answers
36 views

How to bypass “allowed values” validation for a select field (list_string)?

At the user account form, I've created two select fields (of type list_string) for state and city. The state field has a list of states for its allowed values config, and the city field has no values ...
-1
votes
0answers
14 views

ajax with hook_form

how to use ajax callback on hook_form_alter ? i can modify title and value the field on /node/add first i create info.yml then module.. the module contain this.. <?php function ...
0
votes
1answer
35 views

Additional file entity fields in widget_form

I've added additional fields to my file entity types and would like to have them in upload widget, just like file description. How can I add my custom fields element using field_widget_form_alter? (...
-2
votes
0answers
32 views

Trying to prevent Contact Form module from saving submissions to the database [on hold]

I am trying to somehow prevent contact forms from saving to the db when submitted since contact forms is a core module. Any suggestions on possible hooks or some way to follow through with the submit ...
0
votes
1answer
25 views

Form rebuild without using buttons

I'm trying to figure out how to rebuild a form without using a button click trigger. Instead, I'm looking to rebuild whenever a blur event occurs on a textfield. All non-button form types lack the #...
0
votes
1answer
18 views

Alter the wrapper of radios buttons in a custom module

In a custom module, I have created a custom form. In this form, I need to alter the markup of the radio buttons wrapper and add a new attribute. After reading many posts and testing, I can alter all ...
0
votes
1answer
36 views

Datetime validation preventing submission

I have a form which defines a datetime field as follows: $form['register'][$i]['end_date_time'] = [ '#type' => 'datetime', '#default_value' => new DrupalDateTime($data->...
0
votes
1answer
28 views

How to add a region block to the custom template contact form page?

I trying to add a region block to custom template Contact Form page: "contact-message-feedback-form.html.twig" Define a region (like: contact_info) to theme-name.info.yml and add {{ page.contact_info ...
1
vote
1answer
33 views

How to keep checkbox checked after form submit

I am trying to keep checkbox "checked" after form submit and page load. I have following simple code from .module file. <?php function my_module_menu() { $items = array(); $items['...
-1
votes
0answers
6 views

Ajax reverts changes made with hook_form_alter on commerce billing and shipping field

I applied the solution from this issue to my module: https://www.drupal.org/project/commerce/issues/1451132 But when I click on the "Edit" address field during checkout and billing information edit ...
1
vote
1answer
250 views

How can I force the user to register/login first before being redirected back to the current URL?

I'm displaying a form using the Form API under a given URL. User gets this URL and accesses it. But before the user fills out the form, they need to be registered or logged in. How can I send the ...
0
votes
1answer
22 views

How to disable max length validation on an entity form?

How do I disable the #maxlength validation on a field I've added to the user entity form? Let me explain: I want my field to be 10 characters long in the database, so I've set a max length of 10 at ...
0
votes
0answers
11 views

Commerce 2 checkout login pane conflict with registration form

I just encountered strange problem. I am using drupal 8 commerce 2 default "login or guest or register pane" When i try to login with existing user it validate registration required field. Please ...
0
votes
1answer
31 views

How do I render a form from a controller?

Render form in Drupal 8. In modulename.routing.yml modulename.fp: path: '/formpage' defaults: _controller: '\Drupal\modulename\Controller\*Controller::formpage' Write code in controller.php ...
0
votes
0answers
34 views

How to set default value for the type checkbox_tree in Form API? [closed]

I want to set a #default_value for the type checkbox_tree in Form API. The value I set is an array of arraies such as $urlParam['p_c_lv'] and $urlParam['rch']. $form['rch'] = [ '#type' ...
0
votes
0answers
32 views

Updating $form_state of a form from a different form

I have a pretty complex process that combines two Drupal forms--1 widget form and 1 normal form. The first form (WidgetForm that extends the ImageWidget form) will allow the user to open a modal to ...
1
vote
0answers
34 views

Programmatically add more 'paragraphs' in form alter ajax call [duplicate]

I have a content type called repair that has a multi paragraph field (field_products) called Products. In the create new repair form I have an ajax button that fetches N number of products and ...
1
vote
1answer
35 views

Prevent clubbing of server side error messages on top [closed]

I have inline form errors module enabled on my drupal 8 site. The server-side errors that appear on form submission are appearing as clubbed together like below: How to change this error language and ...
0
votes
1answer
33 views

ConfirmFormBase to FormBase

Drupal 8.7.x I have a Form button with a confirmation page to delete an ingredient. I'm trying to convert it to a standard Form that just deletes it without confirmation, however I keep getting an ...
0
votes
1answer
56 views

Custom formatter for paragraphs field

I want to build a custom formatter for a paragraphs field that renders some of the fields of the paragraph. However, I don't know how to access the single files of the paragraph field. So far I've ...
0
votes
1answer
67 views

How can alter the select options provided by Simple hierarchical select?

Simple hierarchical select is used to display Taxonomy as a select field in my existing content type. So I'm trying to alter the value of it. Even tried using hook_form_alter but didn't work. So is ...
0
votes
0answers
37 views

Get the value of password confirmation field register

I want to use the default register form to get the value of the password confirmation field on register. If a user change his password it will call my API ans send the new information. I can't find ...
0
votes
0answers
38 views

How to get the file ID using managed_file on custom form?

In Drupal 8, I have a custom form that I built using the Form API in a custom module. I am trying to upload a file using managed_file field. For some reason I can't get it to give me the file ID no ...
1
vote
2answers
55 views

How to programmatically build a page and a form in the same page

What I'd like to do is build a page with two things: On one half of the page, custom markup with data from Drupal. On the other half, a custom form also submitted to Drupal. There are a lot of ...
0
votes
2answers
53 views

Run validation callback before ajax

The submit element on my form uses an ajax callback which sends out an email. I have a validation callback which I've added to this form, but it gets run after the ajax callback and so the email will ...
-1
votes
1answer
39 views

Webform element validation custom module

I want to add a custom validation to text input, I followed the instruction provided in https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-element ...
0
votes
1answer
74 views

Why is $form array empty when extending FormBase or NodeForm

Why is $form not upcast with the requested bundle's fields for the default Form Mode for GET requests; and with the entities' values for other method requests? My form: namespace Drupal\tam_api\Form;...
0
votes
1answer
21 views

How to set “Language Selector dropdown” required in node form

I want to know How to set "Language Selector Drop-Down " required in node form? I tried to do this via hook_form_alter, but it seems $form['language'] is not created in this hook ! Is there any hook ...
0
votes
0answers
49 views

Set Custom Form Element Value in Extended LinkWidget Class

I have a class extending LinkWidget and would like to add a new form element. I have omitted all code except what I have added: class CustomWidget extends LinkWidget { public static function ...
0
votes
1answer
33 views

How can I set value to hidden field (Form Api) and send them with post method?

I’ve created a form with Form Api in a custom module. I send datas with post method to a web service. In buildForm() $form['mode'] = array( '#type' => 'hidden', '#value' => '...
0
votes
0answers
17 views

$form_state->setError on autocomplete field

I have a form with custom validation and an autocomplete field. I have no problem to set errors for text fields, for example for a List (text) field I can say $fss = $form_state->getValue('...
0
votes
1answer
62 views

how to extend FormBuilder::processForm from multiple API endpoints in one class

I'm trying to consolidate my form processing by entity_type, without rebuilding the forms (just using the default forms provided by Drupal. I have dynamic routes pointing to a _controller::method. I'...