Stack Exchange Network

Stack Exchange network consists of 175 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
0answers
9 views

Ajax Form “back to form” link not reloading form via ajax

This just started happening today. We have a site form that built with 'Ajax' turned on. The form submits, and ajax displays the 'confirmation' message with the 'back to form' link. When clicking '...
0
votes
0answers
40 views

Fieldset collapsed by default

I'm working on a Drupal 7 project where I use the form API to build a form. I want my form's fieldsets to be collapsed by default. I use the following code: $form['fieldset'] = array( '#type' =&...
0
votes
1answer
27 views

Webform Validation Allow Lowercase Only

I have an email field in a webform that will trigger a rule that checks against that field against a user's email. The issue is, rules is case sensitive so if the webform field had capitals, and the ...
1
vote
1answer
16 views

Field value empty in submitForm

I've got a form field that is empty ("") when I submit my form and I cant figure out where I am going wrong. The field in question is reason - as in the reason why this record is being changed. I also ...
0
votes
1answer
34 views

How to compare before and after state in whatever_submit($form, &$form_state)

In a custom module, I have a form allowing some Create/Update/Delete data in a specific table of the database. In the submit part of the code, I'd like to compare 'before' state (what was displayed to ...
0
votes
1answer
130 views

How to display form element and label inline

This must be simple, but I cannot find the answer. I want the label and the textfield on the same line. I tried this: 'odt-filter' => array( '#type' => 'textfield', '#title' => 'Filtra',...
1
vote
1answer
32 views

Configuration form confirmation

I have a configuration form which extends ConfigFormBase. How can I add a confirmation popup/page to give a message to the user that some field has certain value and do you wish to continue form ...
2
votes
0answers
54 views

Apply constraint conditionally

I've just started to use Drupal 8's Entity Validation API and I'm applying constraints to entities in the following way using hook_entity_bundle_field_info_alter: ...
1
vote
1answer
61 views

Get form values into hook_node_insert / hook_node_update

I need to get in hook_node_insert and hook_node_update the value of a field I manually added to a form. function hook_form_FORMID_alter(&$form, FormStateInterface $formState, $form_id) { $...
0
votes
0answers
8 views

Limit theme_webform_element() to One Form for Placing Description Above Field?

I have a very long webform, more than 200 fields, where the description needs to go above the input/textarea and below the label, instead of below the input/textarea. I am using webform 7.4.x and I ...
4
votes
1answer
148 views

How to add autocomplete to a textarea on a form?

I would like to add autocomplete functionality to a textarea form element in Drupal 8. I have a fully functioning custom textfield which has autocomplete working on the same form. I have confirmed ...
0
votes
1answer
37 views

Using JCF with dynamic forms

I want to use Javascript Custom Forms (JCF) to get more attractive and consistent looking forms on my Drupal 7 site. I've got it working to a degree, however when the form changes with AJAX, the new ...
2
votes
1answer
22 views

Override one line in core tabelselect jQuery behavior so custom checkboxes aren't affected

I have created a custom table using a Form API tableselect element, and within my table, I have embedded a checkbox form element that is checked based on an entity field (see here for details). The ...
1
vote
0answers
26 views

How to set fields (widgets) to readonly in hook_form_alter

Some fields of my nodes get regularly updated by an external datasource and therefore should not be edited by editors in Drupal. But for UX reasons I still need those fields visible on the edit form. ...
0
votes
1answer
48 views

Modify/Alter Password Policy Constraints Text

I'm looking for the easiest possible way to modify or alter the password policy constraints error text. The following is the default the users see. The password does not include enough variation to ...
0
votes
1answer
82 views

Custom Ajax forms with managed_file form element

We have a form with three fields - where depending on the value of the first select field, we will show the other two form elements - one select field (the options depends on the value of the first ...
0
votes
1answer
28 views

file name constraint in form

I've got a basic field constraint figured out (per question here: Validation constraints on form fields ignored ) Next, I want to constrain the main image field to limit the file name. For example, ...
0
votes
1answer
54 views

Display entity as options_select multi-select

Below is my code for the view. I have tried multiple = true, multiple_values=true, multiple = multiple. None have worked. ->setDisplayOptions('form', [ 'type' => 'options_select', '...
0
votes
1answer
134 views

Validation constraints on form fields ignored

Trying to figure out custom validation with constraints, but no luck yet. Right now, my form posts content and gives no errors when form is filled out incorrectly. (Please avoid suggesting ...
0
votes
2answers
30 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
29 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
170 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
28 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
42 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
39 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
28 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
14 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
48 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
30 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
46 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
23 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
78 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
17 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
239 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
65 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
107 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
17 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
16 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
22 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
52 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
29 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
26 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
39 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
22 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
103 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
31 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
34 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
131 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
38 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
72 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 ...