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

Make a password security check for the register form

I have a register form that is output in a controller using the following code. $form = $this->getUserProfileForm(); return [ '#theme' => 'maubl_user_inscription', '#form' =&...
0
votes
0answers
11 views

Getting multiple inputs with custom field

I created field for timeline and I selected unlimited for " Allowed number of values " and I "placed" this field to my custom type, After saving content I`m getting multiple instances of this field ...
0
votes
1answer
13 views

How to add class to the options for type radio present under radios?

function template_preprocess_bef_radios(&$variables) { $variables['children'] = Element::children($variables['element']); _bef_preprocess_nested_elements($variables); foreach($variables['...
0
votes
0answers
14 views

Show throbber when views exposed form submits to get results from view

I am using Views Database Connector module to fetch data from a MySQL external database on Drupal 8. The view has certain exposed filters. Due to the large set of data I want to display a throbber/...
2
votes
4answers
42 views

How can I use the core link field widget with title and URL in a custom form?

I want to add a link field to my custom form. Below is the code that I have been trying to use but no success. So can anyone let me know how to use core link field in a custom form in Drupal8? The ...
0
votes
1answer
20 views

How do I make a form field go back invisble after I uncheck a radio button?

I'm currently building a form where the goal is that the administrator will have to choose between 3 radio buttons. If one click on any of the radios, a specific field shows up (There are 3 fields set ...
-3
votes
0answers
13 views

Using contact forms with GraphQL in Drupal 8 [closed]

Can someone give me a solution for using forms with GraphQL in Drupal 8? I am willing to use any kind of form (contact, webform...) I just need to send the form to the frontend app and receive the ...
0
votes
1answer
18 views

Entity Validator failing Integer for not being integer

I have a custom entity with an integer field with the following baseFieldDefinition: $fields['permission_level'] = BaseFieldDefinition::create('integer') ->setLabel(t("Permission Level")) ...
0
votes
1answer
26 views

Altering UserPasswordForm redirect with a custom submit

I want to alter the redirect of UserPasswordForm from Drupal’s core, I did this function maubl_user_form_alter(&$form, FormStateInterface $form_state, $form_id){ switch($form_id) { case '...
0
votes
0answers
16 views

Ajax call in form alter of inline entity form

Inline entity form is using in bricks. In that Inline entity form, there is 2 dropdown fields available . i want to form alter in that Inline entity form, so that selection of one dropdown value, ...
0
votes
0answers
16 views

Lost name attribute after recharge select field with ajax callback [duplicate]

I have a great trouble with ajax callback, I need to recharge a select field, the callback goes right, but, the returned field in ajax request goes without name attribute, so, I lost it while submit ...
0
votes
0answers
17 views

user_login_submit doesn't work when called in an inner function

We have a shared register function that multiple pieces of our app use. When registration is successful, we log the user in. But for some reason, when a user completes this project via browser in the ...
0
votes
0answers
29 views

How do I programmatically add fields to Paragraph types?

I have one paragraph type of Product. and I have to add one field to paragraph product programmatically, how can I achive this. function my_module_field_widget_paragraphs_form_alter(&$element, ...
0
votes
0answers
20 views

How to select a default “text format”? [duplicate]

I created a "Text (formatted, long, with summary)" field. If I select a "Text Format" in "Default Value" and save it, it does not save and always returns to "Plain Text". The only way to keep the "...
3
votes
3answers
89 views

How to determine if loading a form or submitting a form in hook_form_alter?

I am trying to put a simple message at the top of a node edit form when a user is creating a new node. I added a \Drupal::messenger()->addMessage() inside a my form_alter hook but this prints when ...
1
vote
2answers
47 views

How can I programmatically add a field to a field group?

I have tried this code but it is not working. $form['field_test'] = [ '#title' => t('test'), '#type' => 'radios', '#options' => [t('A'), t('B'), t('C')], ]; $form['#group_children']['...
2
votes
1answer
26 views

How do I render a submit button so that it's disabled initially and enabled by JavaScript?

We have a form that includes a React JS frontend component. The component collects some required information, which the React component then supplies to the backend by populating a hidden form field. ...
0
votes
1answer
34 views

Create a draggable table and save weights

I'm struggling a bit with creating a draggable table. I want to have a table that lists node labels, where it's possible to rearrange the order of the nodes. The new weights shall be available when I ...
1
vote
1answer
33 views

Limit multiple fields node add form

How can I (either with a module or programmatically) limit the number of values for multiple fields? For example, the user can add only a single value for field A OR field B OR field C. The total ...
2
votes
1answer
47 views

How to create a select drop down that opens a URL?

I have a select drop down. When the user selects a value from the drop down, the user will then click on a button and based on what the user has selected it will open a url in a new tab. While this is ...
0
votes
1answer
56 views

How to programmatically render a webform to display specific Elements

I have tried this way but not able to hide "confirmation_id" element. public function buildForm(array $form, FormStateInterface $form_state, $sid = NULL) { $my_webform_machinename = 'request_form'; $...
5
votes
1answer
57 views

How to save custom label as parameter for a custom entity_reference field widget?

I am creating a custom field widget for an entity_reference field. This has a custom select field and an Ajax Submit button. Once the user selects an option (entity) from the select_field and submits ...
2
votes
2answers
227 views

How can I make the coupon code field in commerce mandatory?

Using D7 commerce coupon/discount modules. I need to make the coupon field mandatory. Every order needs a coupon code entered. There is no standard "required" checkbox on the field and I tried using ...
0
votes
0answers
37 views

How do change the value of a session before form submission

I created a custom module that allows users to enter their information, and during the form submission, I set a session with the name that they type in the form: $session = \Drupal::request()->...
0
votes
1answer
15 views

Alter Add to Cart form POST data provided by #action

I am going to be phasing out Drupal Commerce on our website in favor of a new custom built application that is hosted at another URL. Without completely rebuilding everything I am trying to override ...
0
votes
3answers
41 views

Strange behavior: Extra css classes are NOT merged with the 'Search Block' form tag classes but with those of BLOCK wrapping the form tag

i'm experiencing such 'strange' behavior with Drupal (v8.7.10) when trying to add css classes to the default Search Form form tag using MYTHEME_form_FROM_ID_alter hook, the classes are NOT merged with ...
1
vote
0answers
39 views

Inline entity form field alter

I am using Drupal Commerce. For the Variations, I am using multiple add /remove via AJAX. I need to make field readonly. 0 -> <input type="number" name="variations[form][inline_entity_form][...
0
votes
1answer
32 views

Encode Forward Slash with &#x2F in Text area drupal 7 form

I am facing issue in Encoding forward slash with &#x2F in my custom drupal 7 form. I have a text area field with name "Address", i am using check_plain for encode special characters, All HTML ...
0
votes
1answer
27 views

How to add HTML5 attribute “autocomplete” to form fields?

According to an accessibility test, I have to add the HTML5 attribute "autocomplete" an the proper tags to all form fields on my website where the user fills in his/ her personal data. E.g. "Your E-...
1
vote
1answer
26 views

Change views exposed filter value only on page reload [duplicate]

Is there a clean way to alter a View exposed filter field, but only on page reload and not each time you submit the exposed filters form ? Example I have a View with exposed filters. When a user is ...
3
votes
1answer
204 views

Is there any convention about the form IDs?

Is there a convention for the form IDs? I see that core sometimes uses module_name.form_name and sometimes module_name_form_name. In my case, I'm using module_name.form_name.
0
votes
0answers
32 views

Make field required if entity reference field is filled

I'm trying to make some fields required if an entity reference field is filled. This is the code I currently have: $form['node'] = [ '#type' => 'entity_autocomplete', '#title' => $this->...
1
vote
1answer
32 views

Why doesn't the batch process start?

I've created a class that extend the 'FormBase' class to create a form where I can upload a XLSX file to import into custom DB table. To process the import I would use the 'Drupal batch process' to ...
0
votes
2answers
26 views

Form submission handler is not executed

In a module, I am using the following code. function mysimple_form($form, &$form_state) { $form['#method'] = 'get'; $form['#action'] = '/buy/{_val_}'; $form['search_location'] = array( ...
0
votes
2answers
52 views

How do I programmatically attach a file to a file field in a node? [closed]

I have a custom content type with a file field. I am trying to attach a file uploaded through a custom form to the custom content type. I am able to load the node and update all the other values of ...
0
votes
0answers
26 views

Webform Multi-step validation

I have a multi-step/page webform. It works fine. I have on one page two date fields. One field must be on or after the other and thus I want some validation. No problem I followed the tutorial ( How ...
-3
votes
1answer
53 views

The form has become outdated. Copy any unsaved work in the form below and then reload this page [closed]

How I can fix the error? The form has become outdated. Copy any unsaved work in the form below and then reload this page. I get the error when I try to render a form in another form. I think it can ...
1
vote
1answer
57 views

entity_autocomplete field thats added by ajax is not working

I have a field im adding to a node-edit form by ajax. the field is a simple taxonomy auto-complete field. when I add it directly in my form_alter it works, but when it's added by ajax, The ...
0
votes
1answer
17 views

Is there any elegant way of excluding form element from the `values` array of the `FormState`?

I know that the values array can be cleaned up in the validation or submit callback, but can we somehow mark the element itself to be not put in the values array of the FormState?
0
votes
0answers
15 views

How can I display custom error message using ajax submission?

I use the following code to submit form data using ajax: <?php namespace Drupal\ajax_form_submit\Form; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormBase; use Drupal\Core\...
0
votes
0answers
26 views

How to wrap Paragraph fieldgroup horizontally

I want to display a few fieldgroups inside of a Paragraph side-by-side horizontally when in node edit form. I gave each fieldgroup the class .popular in the GUI in manage form display. The fieldgroup ...
3
votes
2answers
51 views

Unable to retrieve uploaded file in submit handler

I'm creating a custom form with a file upload field that will have its contents read, processed then sent to an external API. The problem is whenever I upload the file the field for it appears to be ...
0
votes
0answers
5 views

How do I save a file's path in a view's plugin module scenario?

I'm building / improving an existing custom module that initially allows a user to select a CKeditor textarea as a Header for any view, where every single view can all have different images. My goal ...
0
votes
3answers
40 views

Can I create a form with a route like this /rooms/{node.alias}/booking?

I'm working on a booking project and I have to create a form for reservations. I have created the accommodation content type and the url_alias for this is: /rooms/[node:title] Example: /node/1 = /...
0
votes
0answers
18 views

dropdown multiple values

I am trying to display multiple values of drop down and store it to the database. How could I do that? Any help would be appreciated. $form['options'] = array( '#type' => 'value', '#...
0
votes
0answers
42 views

How to add Conditional Fields in Paragraphs

I was able to add Conditional Fields in Paragraphs using this article https://agaric.coop/blog/conditional-fields-paragraphs-using-javascript-states-api-drupal-8#comment-209 But it controls and hides ...
0
votes
2answers
64 views

Select all checkboxes of an entity reference field on creating a node

Drupal 8.7.x For one of my content types I have an entity reference field referencing a taxonomy vocabulary. I have a lot of terms in this vocabulary which makes it tedious to check all the ...
0
votes
0answers
6 views

Form still submitted after form_set_error() is invoked [duplicate]

I've a case which is driving me nuts. Form is still submitted after form_set_error() is invoked for an element. I have in form alter function custom element_validation $form['field_test']['#...
0
votes
0answers
33 views

Tableselect with return new response doesn't work

I'm newbie in drupal and I want to create contact list with dynamic search on ajax. I want to ajax load my tableselect. So I use return new Response(render($form)); where the form is tableselect. I ...
0
votes
1answer
42 views

Display the results of a form submit on the same page just under the form

I have created a form and it takes in 3 values which are Brand, Item and Zipcode. The values are queried and the results are fetched the database table. I want the results to be shown in a table ...