Questions tagged [forms]

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

0
votes
0answers
9 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
19 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
21 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
43 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
13 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
24 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(&$...
0
votes
0answers
11 views

Email misses fields from form

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
23 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
13 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
15 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
30 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
19 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-...
1
vote
0answers
92 views

Why isn't my custom Form API #states applied in my webform yaml editor working?

I have the need to set visibility state of a checkbox option in one question (Table checkbox select) based on the value of another checkbox in the same table. I also have other scenarios where I would ...
0
votes
0answers
20 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
1answer
60 views

How do i use onHourShow callback in a date_popup control with the Form API [closed]

On my form I have a date_popup control: $form['order-group']['delivery'] = array( '#title' => t('I Need The Equipment Ready By'), '#type' => 'date_popup', ...
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
20 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
27 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
26 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
26 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
21 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
25 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
26 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
51 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
votes
0answers
15 views

Confirmation popup Box according to a condition on submit button

I am using Drupal 7. In my list I have 2000 subscribers. Now I want a confirmation box before executing the form. The only issue is If I have more than 20 users I want the confirmation form to ask ...
1
vote
0answers
17 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 ...
0
votes
0answers
32 views

Ajax implementation in exposed forms

We use to add property '#ajax' to a form element in our form array, to trigger an Ajax response and it works fine except in case of views exposed forms. This doesn't work in case of views exposed ...
1
vote
0answers
27 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
21 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
44 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
29 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
26 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
16 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
20 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
29 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 ...
1
vote
2answers
38 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, &$...
-4
votes
1answer
34 views

Calling Drupal Form from non-Drupal 3rd Party Website [closed]

I have an existing non-Drupal 3rd party site and I am trying to submit a form request to a site written in Drupal. For some reason, the request does not process. I'm not familiar with Drupal and would ...
0
votes
0answers
22 views

form : I need to prepopulate an entity reference multi value field depending on select list

I need to prepopulate an entity refence field depending on a list selection field. If the user select liste "administrator" then ajax need to prepopulate the field with users asssociated to this list....
0
votes
2answers
33 views

Get value of programmatically (form_alter) added fields at form submit

I'm altering a node creation form using the form_alter hook in a custom module. In this particular case, I'm adding an email field which is not part of the content type structure. At the node creation,...
1
vote
1answer
21 views

Set value on a new term based on a vocabulary custom field

I want to set the value of a field of a term based on a custom field set on the vocabulary. Basically if the vocabulary promote_to_index field is checked I want to the field_index_page of the term ...
1
vote
2answers
27 views

Set a multiple field value on a form

I use this field definition in the entity "message" class. $fields['fichier'] = BaseFieldDefinition::create('file') ->setLabel(t('Fichier attaché')) ->setSetting('file_directory', '...
0
votes
0answers
8 views

Ckeditor with programmatic text_format field

I have ckeditor installed on my site, and when I use filter formatted textareas on my website where admin pages or fields were created using the UI, the ckeditor replaces correctly. When I use the ...
0
votes
0answers
26 views

Get input label on input.html.twig file

I'm working on an input.html.twig file. I need the label name of the input for class and other reasons, but for some reason, I can't figure out how to grab it. I thought it would be part of the twig ...
1
vote
2answers
71 views

How to call a function in a form from another form? [closed]

I have 2 forms: distribution_inscription_table_form and distribution_inscription_for_user_form in the same custom module (amap). namespace Drupal\amap\Form; use Drupal\Core\Form\FormBase; use ...
0
votes
0answers
14 views

How do I use the DateFormatter? [duplicate]

I am trying to use the DateFormatter so I can convert my unix time-stamp into a usuable date stamp that will be set on a custom form. This is my code: $time = \Drupal::time()->...