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
16 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'...
0
votes
0answers
34 views

How to get identifier for menu link item in form hook?

How to get something unique (like 'menu link id' mlid in Drupal 7) in the form for editing one menu link item? hook_form_alter(&$form, FormStateInterface &$form_state, $form_id) { $mlid=... ...
0
votes
1answer
40 views

Programmatically change the weight of a form element

I have a user activation/registration form with different attribute like Captcha and security questions which are coming from different modules. I want to change the display order of form elements. ...
0
votes
1answer
13 views

Hooking into page specific instance of checkout flow form

I'm working on manipulating the buttons used for the checkout flow of using D8 Commerce 2. I'm using MYMODULE_form_commerce_checkout_flow_multistep_default_alter but its changing both the form buttons ...
0
votes
0answers
16 views

How do I programmatically get the value of a Markup module field when validating the form

I'm not able to access the content via traditional methods like: $form_state->getValue('field_canvas_markup') The field doesn't appear next to other fields in Kint. Here is the code I have right ...
0
votes
1answer
22 views

How to change the value of the Submit button text when extending ConfigFormBase

I need to change the value of the Submit button text when extending ConfigFormBase. What is the correct way to do it?
0
votes
0answers
31 views

Save value in form with multiple instances in same page

This is my buildForm function: class NewsletterForm extends FormBase { // ... public function buildForm(array $form, FormStateInterface $form_state, $newsletter_list = NULL) { $form_state->...
0
votes
1answer
52 views

Adding #ajax callbacks to form elements in HOOK_form_alter()

I'm trying to add an #ajax callback to a select element on a form that is created in another module on a Drupal 8.x site. When I add the #ajax callback using HOOK_form_alter() in my module, the Ajax ...
0
votes
0answers
21 views

Ajax based form doesn't work on new from element [duplicate]

I am creating some dynamic form element based on the dropdown selection. There are max 3 dropdowns and I want to run ajax on each dropdown on change event. When I clicked on the first dropdown(Level ...
0
votes
0answers
22 views

Get key of select list in webForm

For example, i Have webform There is a field with 3 options in allowed values, like option1, option2, option3 i want if i select option 1 get key of option
1
vote
1answer
38 views

Focus problem when Ajax call for multiple fields calling the same callback function

I have implemented a custom form. I put same Ajax callback function for multiple field. When one Ajax call completes, I click on other field. But I can't unfocused previous field. Sometimes the Ajax ...
0
votes
0answers
12 views

Uploading xlsx-file changes permissions of the file? Errors when loading via PHPExcel

My goal is to let the user upload a xlsx-file and then read the file to create objects. So i created a file upload page in my custom module where the user can upload a file via the 'file' form field ...
0
votes
0answers
10 views

Set a field value with FAPI states

Does anyone know if there is a way to set the value of a field with states? E.g. If "this" is checked, set input value to "0" Something like.... $form['booking_process'] = array( '#type' =&...
0
votes
0answers
27 views

AJAX in callback function

I'm trying to convert old code written in standard HTML/PHP/Javascript/JQuery into a format (more) consistent with Drupal. The code consists of a form with interactive elements (regulated by ...
0
votes
1answer
69 views

Hide fields in Paragraphs conditionally using Form API #states

Because the Conditional Fields module doesn't work with paragraphs for Drupal 8, I've followed the instructions in Conditional Fields in Paragraphs Using the Javascript States API for Drupal 8 to hide ...
0
votes
0answers
46 views

Why Form Api behaves differently in route and in custom block?

I’ve encountered this issue several time and I don’t know why. I know this not so easy to reproduce but maybe someone has an explanation. I’ve built several custom modules which return datas from ...
0
votes
0answers
18 views

Custom field validation condition not working

I have created a custom form validation. I am using webform module to build the form. in _achva_tz_validate function there are two fields that have the same validation. The second field, zug_id, is ...
0
votes
1answer
35 views

hook_form_alter() on a view exposed filter form

I am trying to add a disable attribute in a field using the hook_form_id_alter function. I created a module and built the function function disableIncentiveform_form_views_exposed_form_alter(&$...
1
vote
1answer
67 views

Email misses fields from form [closed]

This is regarding a Drupal 8 site, specifically Drupal 8.7.1 and the "Contact" module (with Contact Emails, Contact Storage enabled). The issue that I'm running into is some of the fields are not ...
0
votes
0answers
13 views

Adjust block according to stage in multi-step form

I've build a multi-step form using the following tutorial. Which is quite nice! Can I also change a block based on the step you're in? I'm my case I have an activity registration form, build ...
0
votes
2answers
28 views

How do you use hook_form_FORM_ID_alter() to alter the USER EDIT form?

I'm trying to mark fields on the /user/_uid_/edit screen as disabled. These are custom fields I've created in /admin/config/people/accounts/fields in D8. I have this code for another node entity type....
0
votes
1answer
22 views

Skip a form step programmatically in simple_multistep module

I am trying to skip a step in multistep node form using Simple Multistep module. I have tried following snippet that works pretty good to skip one step. $skipStep = $form_state->get('...
0
votes
0answers
16 views

Cannot get form values set in a ajax callback

In the hook_form_alter, I add 3 textfield form elements and 1 button with ajax callback: function zwznertags_form_alter(&$form, &$form_state, $form_id) { if($form_id == 'book_node_form') { ...
0
votes
0answers
35 views

Delete records from database pressing a button in twig

Drupal version: 8.7.x I created a module that retrieves meals based on the given ingredients. I display the ingredients with a delete button and the meals underneath them. However I don't know where ...
0
votes
0answers
32 views

How can i do Webform field custom validation

I want to do a custom validation for a field in some of my webforms. I came across this code: https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-add-custom-validation-to-a-webform-...
0
votes
0answers
24 views

How to set an array of hidden form fields using $form_state->setValues

I want to set hidden fields (permission by field) of a form in Drupal 8. The fields in the form have the names field_pbf_municipality[0]['target_id'] field_pbf_municipality[0]['grant_public'] ...
0
votes
0answers
21 views

Modifying Page Title To Be Separate From Browser Title [duplicate]

I have a module that contains multiple forms, each form in its own file. I need to modify the page title such that it is different from the browser title for several of these pages. The name of the ...
0
votes
0answers
51 views

Drupal 8 : Multiple Submit Handler

I am using Drupal 8.6 for creating custom module in Admin. I have a custom form where i have to use multiple submit button for form submission. I am not able to submit the my form to specific function....
0
votes
1answer
16 views

Form with manged_file filed is not submitted?

I have a form in my drupal module. in my form, I have used manged_file field. form name is "difference_form" and I have created two functions. one is "function diffence_form" for form definitions. ...
0
votes
0answers
28 views

Initial values in forms elements

When I create a form (using form api) I need, sometimes, to assign a default value to form elements, or to create a list for select elements, under certains conditions. In this cases, I need to do ...
0
votes
1answer
45 views

How to add unique class to each checkbox elements

I am displaying checkboxes using form API in Drupal 8. For functional and theming purpose I need to add unique custom class to each checkbox element. Is there any way to add classes to each checkbox ...
0
votes
1answer
36 views

How to modify a form to have some field surrounded by 'Details'?

I created a custom content entity with Drupal Console. Three of its fields are defined this way: // ---------------------------------------------------------------------------- $weight++; $...
0
votes
1answer
27 views

How can i add ajax callback to checkbox in drupal form?

I am using taxonomy manager module I want to add ajax callback to checkbox tree view for checkbox is checked condition but it is not working can some one please suggest me. I have modified the code ...
0
votes
1answer
77 views

D8 | Custom Form managed_file field limit number of upload files

I have a custom form in D8. Form has managed_file field. I am facing challenge regarding the limit of number of files upload to this field. I have to make this managed_file field to upload only 3 ...
0
votes
2answers
28 views

How do I get the form submitted data in a custom module? [duplicate]

I have create a webform in Drupal 7. I want to access the submitted data in a custom module. I used my_module_form_submit($form, &$form_state) but no data has been found. Please Help.
0
votes
2answers
27 views

just want to change checkbox value while submit

I am using drupal 7: $form['title']['#tree'] = TRUE; $form['title']['node_first'] = array( '#type' => 'checkboxes', '#options' => array( 'value' => $value->title, ), )...
0
votes
1answer
56 views

print data to twig file from custom form submit via controller

I have created a custom form, and I'm passing data to twig file from submitForm function as follows public function submitForm(array &$form, FormStateInterface $form_state) { $form_state->...
1
vote
0answers
28 views

scrolling after posting drupal ajax form

I am working on an existing site which has a Drupal 8 multi-step form which uses Ajax Upon submitting the form (on the final step) the page scrolls to the top where a thank you message has been ...
1
vote
0answers
29 views

Have Value Selected but Label Showing in Views Display Plugin

I am working on a custom Display plugin for Views. In my buildOptionsForm() method, I have the following: $form['inherit_yaxis'] = [ '#title' => $this->t('The title'), '#type' => 'radios'...
0
votes
0answers
22 views

How does the register form in the user module load ImageWidget?

I want to use the user picture widget on the user register form to capture an image. So for my custom entity form I'm using the managed_file as such modules/custom_module/src/CustomEntityForm.php ...
0
votes
0answers
50 views

dependency injection by using $this when not in object context

if i´m using the codesniffer function i´m getting two warnings about: 155 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead If i´m changing the line from: $...
1
vote
1answer
46 views

Possible to theme the form's elements with own twig?

I was thinking to get twig outputs so I could use these twig variables on a form.html.twig such as below: <div class="row"> <div class="col-md-6"> {{ form.name }} ...
0
votes
2answers
45 views

Can't find the cause of this error

I am working through a Drupal 8 module building exercise from YouTube and I am not able to figure out what is causing an error. The relevant page loads and displays the form but I get the following ...
0
votes
0answers
16 views

How to set a node as context?

I have a little web app where I have two node types: Customers (/customer1, /customer2) Notes about customers The notes about the customers have an entity reference to the customer. I like to create ...
0
votes
2answers
32 views

Ajax error render

I receive this error message when I try my custom form in Drupal 8. User error: "0" is an invalid render array key in Drupal\Core\Render\Element::children() This is the code I am using namespace ...
0
votes
0answers
24 views

Download a file and redirect to the form after batch operation

On submitting a form we need to run a batch process that writes to a CSV file. Once the batch process is completed we would like to download the CSV file automatically and redirect back to the form. ...
0
votes
1answer
27 views

Unset widget tab from media browser programmatically

Need to unset a widget tab from media browser based on the condition of media type supported by the field. Media types: Image and Video. For example, There is a field which references image media ...
0
votes
1answer
35 views

Provide autocomplete field with user's Display Name

Drupal core already supports autocompletion of username fields. However is there a way to provide autocomplete for user's Display Name? Since this is a virtual field, a database query with % like ...
0
votes
2answers
42 views

Views callback work only once with advanced form block

this code work but the views is callback only once (reload only once), any idea to reload more than one time ? see in detail on drupal.org function modulename_form_alter (&$form, &$...