Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [forms]

Don't use it for entity or entity field forms.

0
votes
2answers
26 views

Unable to set default value for checkbox form element inside tableselect

I've created a custom table using a tableselect element, and within each row, I have a checkbox form element that should populate the checkbox from a checkbox field in the node. I've tried every ...
1
vote
1answer
26 views

How to make a select form element with textfields for the array id and key?

In a custom module which I'm working on, I have a select list which currently has a hard-coded array of key=>value which could change and I would like to expose these options to the user. I would ...
1
vote
1answer
49 views

How to use ConfirmFormBase to confirm the action of another form?

I have a form that allows users to upload a CSV file. Upon submit, I would like to show a confirmation form ("Are you sure you want to import this file?"). However, the Drupal 8 examples for ...
0
votes
0answers
25 views

How to know the type of store?

Drupal 8 and Drupal Commerce 2.10 I have several types of store on my site and I want to modify the button Add to cart of all the products associated with the store type online (online is the machine ...
0
votes
1answer
24 views

Custom Entity: define a view in entity reference field

I defined a custom entity and for a entity reference field I want to set the view reference widget and a view/ display to be used instead of an autocomplete. I tried many different settings - nothing ...
0
votes
0answers
38 views

Allow Custom Form Field '#default_value' to be 0 in Elvis Operator

Dupal 8.x I have a custom form field where the value could be zero for radio elements: $yes_no_options = [ '1' => t('Yes'), '0' => t('No'), ]; $form['config_name'] = [ '#options' => $...
0
votes
0answers
23 views

How to get a single node field into custom form

I have a custom form in which referenced field needs to be displayed. Here is the structure: Content-Type: Project Reference Field in Project Content-Type: POD Details(Fields- MemberName: User ...
0
votes
0answers
11 views

How to use element validation and form validation on the same form?

I have a custom form I am validating with a custom validation function like this: … $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit'), '#validate' => array('...
0
votes
1answer
34 views

Pass list from Jquery to form

I have an AJAX form that I've created into a block exposed on my current page. I will have an interface that will allow the users to select an indefinite amount of content to be used within the submit ...
1
vote
0answers
27 views

Form alter on date parts

I'm trying to add attributes to a date form field. The field renders as day month year in separate inputs. I cannot work out how to add the form alter to these specific inputs. I've tried ...
0
votes
1answer
37 views

How to validate allowed file types in custom module

I want to validate a field with accepted file type as PDF, XLS, JPEG, JPG, GIF, ZIP, RAR and PNG. I'm getting file types as PDF, XLS etc. here is part of my code. if ($fi_name!='') { if ($...
0
votes
1answer
22 views

States with a variable

I have to do a form and in this form I have a select to choose a value, from this value I load a node and from this node I get a boolean. With this boolean I have to show or not another form field, ...
0
votes
1answer
34 views

Changing form field requirement via ajax

I have a selectbox field, that should change the disabled and required states of another field based on the value selected in the selectbox field. The change must be done via ajax. In my modules ...
0
votes
0answers
12 views

How 'checkboxes' form element supposedly can have #default_value if there is nothing to make this work? Or is there?

So, documentation indicates that 'checkboxes' element is making use of '#default_values' property. There are multiple threads indicating that it's possible, like: Checkboxes: how do I set the default ...
0
votes
0answers
77 views

How to add image field in a custom module form?

In our custom module, mymodule we have a form MyModuleForm where we want to allow for an image to be uploaded or chosen from already uploaded images. Below is the MyModuleForm.php file, but cannot ...
0
votes
1answer
39 views

Posting to a form via external URL

I am writing an application (non-Drupal) that is POSTing to a 3rd party public form written in Drupal. The problem I am running into is that the 3rd party form never processes the request, it only ...
0
votes
1answer
59 views

Programmatically set value of Boolean radio button field in form

I am using a custom field in the profile2 module for when a user registers. The field is a Boolean field using the radio button widget. I want to programmatically set the value for the field using ...
0
votes
1answer
16 views

Themeing custom form as table and getting updated field values on submit

In my attempt to create a table that shows all of the locales for a node and contains two editable fields, I've come up with the following functions: function language_dashboard_overview_form($form, &...
1
vote
0answers
12 views

How can I group checkboxes in my custom ER widget?

I have created custom entity reference widget. Basically I need checkboxes inside my form element. But they have to be grouped by "Row" field presented on referenced entity type. I'm not sure is it ...
0
votes
1answer
21 views

lost password “user-pass” form no more redering

We didn't touch our templates and the "lost password" form is no more rendering. here is my template code working fine with $login_form. <div id="login-container"> <div class="login-hint"...
0
votes
1answer
40 views

How to define template suggestions for node add and edit form by content type?

I have a content type Project and it has a more than 100 fields in the node form. The form fields are grouped in different section and category. I tried to use a field_group module to group and ...
0
votes
0answers
23 views

AJAX Form Not Submitting Until After Cache Clear

I'm working on a module that needs to add a form to a page that submits via AJAX. My form consists of a text field and a submit button with callback: $form['my_text'] = [ '#type' => '...
1
vote
1answer
19 views

Change the display name of a default field in Contact Form

In Drupal 8, I LOVE that there are default fields in Contact Forms for Name, Email, Subject, and Message...but in several of our forms those labels don't make sense. For example, one form's primary ...
0
votes
1answer
23 views

Date popup field won't display in tableselect element

I am attempting to embed a couple of date fields within a tableselect element, and after trying to use both textfield and date_popup field types, I can't get either to work. Here's my form function ...
0
votes
0answers
21 views

Entity Form Builder bypasses Access Handler on submit?

I have a ECK Entity, it is allowed to be edited only by admins. Under a custom route /test I load the form with \Drupal::service('entity.form_builder')->getForm($entity, 'default'); Now as an ...
1
vote
2answers
77 views

How to sort language select list on current language context

I have a form with a language field with the language select list widget. The options of this field contains an array with a pattern like ['langcode' => t('language')] Now I want to sort these ...
2
votes
0answers
30 views

How to add a modifier to a form id? [duplicate]

If I form alter a form, I see the form_id as MY_FORM_ID; I see this in the $form_id parameter to hook_form_alter as well as in the $form_state->build_info['form_id']. In the rendered output of the ...
0
votes
1answer
31 views

Form incorrectly displays differently depending on logged in user's role

All logged in users can add a forum node. The current topic is determined by a field in another node (nid=77) and set to the default value for the node being created by this form. While this all ...
0
votes
0answers
61 views

Ajax form: Rebuild form and show popup

On my ajax submit form I would like to rebuild the form and show a dialog. Here's the code I have used. public function buildForm(array $form, FormStateInterface $form_state) { if ($some_condition == ...
0
votes
1answer
23 views

How can I build a redirect from submitted form values?

I'm working on a short weather app. What I want to do, is to catch name of the input of city and redirect users to the city's page URL after submit. function form_findYourCity_submit($form, &$...
0
votes
1answer
43 views

Programmatically render a custom form in a view template while passing view argument to form

I have built a custom form (in its own module using FORM API) and have exposed this form also as a block using Plugin API. I can add this form fine to page and get it to render using Block Layout but ...
0
votes
1answer
38 views

How to display a warning message

I have a form with a required checkbox. If the box is not checked and I confirm my form, I receive a warning with Chrome (see the screenshot). How to display a warning message in drupal ? In my ...
0
votes
0answers
34 views

How to use form input fields nested in tableselect

I'm trying to build a customized, Excel-style bulk edit form for one specific, multi-value field used in multiple nodes. I thought a tableselect form render element would be a good start, but I'm ...
0
votes
1answer
47 views

How do I disable a fieldset?

I read How to unset fieldset in hook_form_alter? to disable fieldsets in an hook_form_alter() implementation, but it didn't work. I tried using the following code, but neither of them worked. // ...
1
vote
1answer
25 views

Custom submission handler doesn't save the node

I have two form submission buttons: the normal one and one added via hook_form_alter. I'm currently using the normal default one as a save button which updates the node content as normal. The second ...
0
votes
1answer
47 views

How to handle Custom Validation in inline entity Form?

I'm using Drupal8's inline entity form and is having issue with writing custom validation. I found few links and wasn't helpful at all. Does anyone know how to handle this?
0
votes
0answers
40 views

How can I translate the “Published” checkbox?

On the node edit form, I would like to translate the Published checkbox in Foo only for a certain content type. Therefore, I implemented hook_form_alter(). I cannot find the label string in any ...
1
vote
1answer
46 views

How to display the path without alias?

With Drupal 8 and Commerce 2.10 I created a php code to display the link of my store. When I go to the link, it displays: https://www.domaine.com/shop/name I want to display without alias: https:/...
0
votes
0answers
37 views

How to insert the store ID in a plugin?

I have a Drupal 8 site with a marketplace (several stores). I want to display in the "review" step of the "Checkout Pane" a checkbox with the sales terms. The terms of sales are accessible for each ...
1
vote
1answer
39 views

With a custom form, how to sanitize user input before query gets to URL?

I followed this tutorial to create a custom Search form that takes users to the main search page with a query in the URL (meaning it uses a get method). This gives me more flexibility than using an ...
0
votes
0answers
25 views

How to use #date_time_callbacks to add jquery time picker

I would like to know how could I attach a jquery time picker to a datetime form element. I've made a module that displays a form. This form has datetime input element and I would like to use this ...
0
votes
1answer
31 views

How to set a multi-value image field's default value from author's profile field on a node create form?

On /admin/config/people/accounts/fields page, there is an optional multi-value image field field_proof_images. There is a content type Proof, I reuse the field_proof_images in Proof. Then on /node/...
6
votes
1answer
559 views

How to prevent an Ajax form from submitting

The below code blocks any non-ajax form from submitting. $(this.form) .on('submit', function(event) { if (/* Some condition */) { event.preventDefault(); } }); In Drupal 8, how can ...
0
votes
0answers
27 views

Set Custom “Paragraph Type Icon” For Paragraph Type With Module During Install

Drupal 8.x I have a paragraph that is installed via a custom module, this is done with .yml files in the MYMODULE/config/install/ directory. I would like to have a custom icon added to the "Paragraph ...
0
votes
1answer
29 views

File upload with auto compression

I have written a module with form api which can upload image with dynamic file name. I want to upload that file with auto compression. I cannot understand how will I achieve this. How can I implement ...
1
vote
1answer
43 views

How to compare text input with a user password stored in the database?

I've been trying to compare password values using a custom form. Actually I want to show a relogin form after a particular amount of time. So I have created a custom form with two fields – email and ...
-1
votes
2answers
108 views

How to display a button with “markup”?

I created a custom module and in the code below the button is not rendered, there is only the text : $form = ['#markup' => '<button type="button" class="btn btn-success" disabled="disabled">...
0
votes
1answer
50 views

How to add a time picker in datetime form elements

I have made a module that display a form. One of the form elements is a datetime field. $form['FirstDate'] = array( '#type' => 'datetime', '#title' => t('First date-time'), '#...
0
votes
1answer
29 views

Manage Form Display - not saving configuration

i'm working on a pretty big User/register site. Today i created some more fields. Now i want to order them properly with the "manage form display" settings like i used to but it is not working. ...
0
votes
1answer
26 views

Elements not showing in $form object

I have a webform with some fieldsets. Within each fieldset is a set of input elements that are the same for each fieldset, and each set of elements has the same machine name. One of the elements is a ...