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
1answer
18 views

Form alter overriding submitted values

I have a form_form_id_alter function that sets some default values and a checkbox checked. If I submit the form, with the checkbox unset and it fails validation, the re-rendered form re-sets the ...
2
votes
2answers
39 views

Automatic username generation from name fields at registration

Drupal core 8.6.5 I am trying to change the user registration process to omit the username field and generate the username from the first name and last name. Since I am new to Drupal and want to ...
0
votes
0answers
8 views

How to clear the publish checkbox in form or form element validation

I have a D8 form where when a test involving the value of other fields fails, if the publish (field = status) checkbox has been checked the validation should fail and the checkbox should be cleared ...
-2
votes
0answers
27 views

How can I build a Presentation Manager? [on hold]

My project's structure: I'm building a Presentation Manager. A Presentation has a title, an image and Slides A Slide has a type (can either be text, image or video) We want to be able to re-order ...
-4
votes
1answer
31 views

Find different node in hook_node_form_alter [closed]

In the function hook_node_form_alter(), i still want to get an other node, because i want to set a field value programmatically in dependencies on the value of an other node (the parent node). But i ...
1
vote
0answers
35 views

How can I add a property definition to an existing field?

I have a file reference field FileItem that has a display and description property but I want to add an extra one. I was hoping I could just override the default widget but I can't use this to store ...
0
votes
0answers
31 views

Form action as controller method?

I'm trying to fix a form that was created using a twig template. The form was not working because there was no action, nor was the form created using FormStateInterface. It's just a block that is ...
0
votes
1answer
29 views

Altering Views Exposed Form Elements and their Associated Labels

I have a series of Views Exposed Forms across a Drupal 8 website. My goal is to generate unique template suggestions so I can theme each individual input and their labels differently as needed. Here ...
-2
votes
0answers
20 views

onchange autosubmit autocomplete not working for safari

I created a custom autocomplete form in Drupal 7. Its working fine for chrome and firefox. but it's not working for safari and Mac. My code: function fitnessHomeSearch_form($form, &$form_state) { ...
1
vote
1answer
23 views

Add another button removes the default values from my fields on node form

I have a node form on which two fields are displaying. One is a list of radio buttons which is required field. I am getting a value from url using arg(3) and setting the default value of that field $...
0
votes
0answers
23 views

Contact form throws “an illegal choice has been detected” error

I try to add a contact form with add contact form from the contact module on Drupal 8 but I have this error when I try to save the configuration: The recipient field is required An illegal choice has ...
1
vote
1answer
17 views

Programmatically disable content translation options in content edit form

I want to programmatically disable the content translation options located at the bottom of the content edit form (see yellow area in screenshot): I know that i can disable the revision information ...
1
vote
0answers
39 views

Validate a field only if the value has changed and/or if it is a new value

I'm building a module that get information from the NCBI database API -- specifically it get's publications, from my group, by using a publication ID. I want anyone in the group to be able to add a ...
0
votes
0answers
12 views

Upload file using File type=“managed_file” disappears immediately when clicked on upload?

I want implement upload zip file using FORM API where I want to show the progress bar for uploading file so I have written code like: $step2['browse']=array( '#type'=>'managed_file', ...
0
votes
0answers
29 views

Embed user edit form in a block

I am trying to embed current user edit form in block. Actually I want just to embed some of the newly added fields. I tried to follow this code: Embed some user profile fields in a block form But I ...
-2
votes
0answers
41 views

How to create depended fields in drupal custom module [duplicate]

I know this has been asked before and I'm trying to use the example at Dynamic select list in the form (dependent dropdown) but I am struggling to get the desired results. I Have a form that presents ...
0
votes
1answer
28 views

Webform Submission Using Rest API POST method

I just created the webform and added fields. I need to create a Webform Submission Using Rest API POST method. I just installed Rest & Rest UI modules for this. But when I try to test my API ...
0
votes
0answers
13 views

Proper Schema file for integer and select

We have a custom module, mymodule that has an admin form where it stores field of type: number and select. I need to create a mymodule/config/schema/mymodule.schema.yml file, but don't know what to ...
0
votes
2answers
29 views

Form multiselect item and url encoding with GET method

I have a form on a Drupal 7 site, which is submitted using the GET method to refresh the page's display using the query parameters. One of the parameters uses the select box, with the multiple option. ...
0
votes
1answer
28 views

Block with form input serving other blocks data

I have a custom module which had a form with some inputs and after submitting it, it creates two tables with some info. I'm now changing the way I show the information. For that, I'm using Panels, ...
0
votes
1answer
22 views

Turn form builder response into HTML

I have a node type called "competition". I can get a form for it like so: $values = array('type' => 'competition'); $node = \Drupal::entityTypeManager() ->getStorage('node') ->create($...
0
votes
0answers
30 views

$form_state->setError not working for add_more buttons

I am altering a paragraphs form to add a validation function to the "Add More" button using this code: [This button add widgets for multiple value fields] function ...
0
votes
1answer
38 views

Getting form variables data into twig templates

I need to pass an array to twig along with the form. public function buildForm(array $form, FormStateInterface $form_state) { $form['job_locations'] = $job_locations; $form['#theme'] = '...
0
votes
0answers
14 views

Index Form API forms with Solr search

My site uses Apache Solr search and Apache Solr Multisite Search. I need to be able to index some Form API forms created in custom modules so that they return in search results. For instance, when a ...
0
votes
1answer
25 views

How do I enable an onclick event in a link on a form?

I am using the following code. $form['test'] = array( '#type' => 'link', '#href' => "javascript:;", '#title' => t('Show'), '#attributes' => array( ...
0
votes
1answer
35 views

Prevent underscores from removing text?

Drupal seems to be removing all text prior to an underscore in my form. This is in the Form.php file of my module implementing Google CSE, so I cannot change the attribute name. if (array_key_exists('...
0
votes
1answer
22 views

Hiding group_group field programmatically

I am trying to hide the group_group (request membership) field for organic groups based on a radio button. Here is what I have done that doesn't work: /** * Implements hook_form_alter(). */ ...
-1
votes
0answers
13 views

Theme Form Elements

I'm using the following to format field elements in my theme: function theme_form_element($element, $value) { $t = get_t(); if ($element['#type'] == 'checkbox') { $output = '<div class="...
0
votes
0answers
7 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
32 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
19 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
14 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
30 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
37 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
27 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 ...
1
vote
0answers
35 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
43 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
4 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
74 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
22 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
18 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
20 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
20 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
25 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
27 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
26 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
74 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
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
47 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 ...