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
22 views

Dynamically set '#prefix' => '<div id=“wrapper_id”>'

I have a form with a select field (where you can select a title of a novel). This select field automatically writes a value (the rspective ISBN of the novel) into a textfield when a novel is chosen by ...
0
votes
0answers
20 views

How to restrict dates in the form widget?

I am attempting an upgrade and I am looking for something that mirrors the functionality of the Date Restrictions module Basically, I used it to set relative limits,, something like no earlier than ...
1
vote
1answer
27 views

Modify existing custom content form

I'm very new to Drupal development and I am completely stuck(. I have a custom content form, where I need to hide some fields in Inline Entity Form. I am trying to write my own custom module to ...
0
votes
0answers
16 views

Displaying input fields on a panel

Is it possible to display the input fields on a Panel so that users can input data into them? I currently have these fields set up on my content types but would much prefer them on a panel. I've ...
0
votes
0answers
17 views

Overriding values in AJAX dynamic form fields

I built a form based on that documentation page: https://api.drupal.org/api/examples/form_api_example%21src%21Form%21AjaxAddMore.php/class/AjaxAddMore/8.x-1.x of course I extended that form because I ...
0
votes
0answers
24 views

Replace select options

I have a form: public function buildForm(array $form, FormStateInterface $form_state) { // Disable caching on this form. $form_state->setCached(FALSE); $scheme_data; // code to ...
0
votes
0answers
57 views

How to disable browser autocomplete for the login form

I would like to remove auto fill user name and password while login or forgot password. I have tried this but its not working: if ($form_id == 'user-login-form') { $form['name']['#attributes']['...
1
vote
1answer
35 views

Error when I try to call a form

Here is my class: <?php namespace Drupal\mais\Form; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\...
1
vote
0answers
50 views

How do I override the registration form?

I am trying to override the user registration form in Drupal 8, using the following code. RouteSubscriber.php namespace Drupal\registration_subscription\Routing; use Drupal\Core\Routing\...
-1
votes
1answer
61 views

How to transfer data from/with PrivateTempStore? [closed]

I have an multistepform which handles sessions and stores like this: https://www.sitepoint.com/how-to-build-multi-step-forms-in-drupal-8/ But i want the option that the user can login in between. The ...
0
votes
1answer
25 views

Get Field Name Being Deleted From Configuration Updates/Delete Form

Trying to get the field_name being deleted when viewing a route like entity.field_config.user_field_delete_form. Example path: /admin/config/people/accounts/fields/user.user.field_name/delete Some ...
1
vote
1answer
39 views

How to get a field third party settings for every content entity forms

Can someone explain or post an example of how to get a third party field settings on every content entity forms? I'm looking for a generic code where a form can be customized (like calling a custom ...
1
vote
2answers
77 views

Download file programmatically

I have a custom module where I need to create a file and download it on form submission. So far, I managed to created the file and save it in public folder, but I cannot find a way to download it to ...
1
vote
0answers
22 views

Drupal won't update textfield from a integer value with no decimal to the same value with a .0 decimal

I am facing a strange situation in Drupal 8 where the value of a text field won't be updated in some situations. Indeed, if the textfield's value is an integer, for instance 19 and I try to update ...
2
votes
1answer
47 views

No default value for '#type' => 'date'?

is there a way to configure a date form so it has no default value? Setting the default value to NULL sets the default value automatically to the current date. /** * @return array */ public ...
0
votes
1answer
12 views

Disable (or workaround) form rebuild with managed_file field

I'm using the Form API to create a custom form. It has a managed_file field and some other fields, some of which are required. If any of the required fields are not filled in, the file upload for the ...
1
vote
1answer
66 views

Select list set default value does not work

I have referenced filed, which works like select list, I want first value be always default value in content edit page. Now N/A is always selected. function theme_form_alter(&$form, \Drupal\Core\...
0
votes
0answers
23 views

Missing values in $form_state['values'] when addding field through _form_alter after AJAX callback

I want to add a couple of fields to a content type form using AJAX and, upon validation, run a custom _submit callback to do something with those fields. My approach: 1. Alter the form adding a ...
0
votes
0answers
21 views

Get data from textfield dynamically in form

I would like to get data from textfield dynamically. Next i want to verify content from field and do sth(without refresh) $form['cont_but']['scan_field'] = array( '#title' => 'Scan:'...
0
votes
0answers
15 views

D8: Embedding View in custom form with exposed filters causes custom submit not to fire

I am trying to embed a View into a custom form which has exposed filters. However when I add the field, it causes my custom submit button not to fire at all. It doesn't even try to reload the page. ...
0
votes
0answers
35 views

Error Passing Function from Form Controller Across Module

I would like to access a function from my Form\Form.php in both my Plugin\Block\Block.php and MYMODULE.module. Related: How to render content generated by controller in custom block? and Inject ...
0
votes
0answers
12 views

Using nested #states with 'visible' causes problems

I have a form with 3 radio fields and a textfield in it. Radio Field 1,Radio Field 2,Radio Field 3 and Textfield I'm using #states to make: Radio Field 2 only visible if certain input from Radio ...
1
vote
1answer
50 views

AJAX button - HTML in #value causes problems

i have an Ajax button, the code looks like this: class coolButtons { public function getFormFieldAjaxButton() { return [ '#type' => 'submit', '#value' => t('<i class=" ...
0
votes
1answer
18 views

How to remove the click event on an Ajaxified form's submit buttons?

I've created several forms with Drupal 8 directly in admin or with Form API. I've added some client side validation with this jQuery plugin : jQuery Validation Plugin. Everything works very well. Now ...
0
votes
1answer
31 views

Custom Save and Unpublished button for node

While clicking Save as draft button, it will save the node but while it have to redirect to the created node it gives error The website encountered an unexpected error. Please try again later. and $...
1
vote
1answer
29 views

How to style a custom theme setting form

I have a set of custom theme settings defined in my theme. They are fully integrated into my theme and appear on the theme's setting page but they are not styled. I use the seven admin theme. I ...
0
votes
1answer
33 views

How to use custom code to change the node form layout and group fields while maintaining values?

I am trying to alter the node form layout in a form alter hook. I altered the node form and added a field set in which I grouped couple of existing fields into a fieldset. Then hid the existing ...
0
votes
1answer
54 views

Unique form per user with custom form class

Not sure if this is a related/duplicate of Generate unique form ID based on context I am hoping I can render a unique form per user with the Form API using a custom form class. What I've seen with \...
0
votes
1answer
84 views

Adding Constraint to Paragraph field

I have a Content Type with a field that references 6 different paragraph types. The field is set up to accept unlimited values. For one of the types I would like to have exactly four values added. ...
0
votes
0answers
25 views

Quantity field and Custom text field is not displaying in add to cart form

My aim is to display two fields in Product page (Custom text and Quantity field). I have created a new custom text field. Finally, I have moved these two fields from hidden to visible mode in Add to ...
1
vote
1answer
39 views

Increase label max length

The default max length for all labels of all field types is 128. The DB can handle 255. So no schema change. How can I change the default max length to 250? I've seen this module https://www.drupal....
0
votes
1answer
58 views

Get an Un-submitted/Active Form Field Value in $form_state?

I am unsure how to get unsubmitted/active form field values from a number/textfield into $form_state. field_count could be saved as 4, then is changed to 115, how do I pass that change to $form_state ...
0
votes
0answers
28 views

$form_state values are empty after ajax $form modification

Im doing a module to generate form validation on field length, first i display a select of availble content types. When the target content type is selected an ajax request display the end of the form ...
0
votes
0answers
28 views

How to programmatically add fields to a node through a module

I've followed a tutorial here about adding a field to every taxonomy and node and I'm getting an error on installing it. I can get the field, widget and formatter to work, just can't get it to install....
0
votes
1answer
71 views

Unlimited Custom Form Fields - Without Ajax

I have a simple form where users can set the number of fields they need. Users may need 100+ fields so I am not using ajax "add more" options. With the below code, everything works (Even though you ...
0
votes
0answers
36 views

How to validated form with Ajax fields

I have a drupal custom form with two ajax dependent dropdown fields and five normal text fields. on form submit, all things are working fine except validation of form fields. when I put validations on ...
1
vote
1answer
24 views

Create config object with array containing key-value pairs

We have a custom module, mymodule, that we want to use to create a config object for so that it can contain an array of key-value pairs. We need to be able to click button Add More on the form that ...
-1
votes
2answers
58 views

messenger()->addMessage not working after a $form_state->setResponse

In the submitForm of a custom form, I have this: switch ($form_state->getValue('suscribe')) { case 0: $iStatus = 1; break; case 1: $iStatus = 3; $sFileName = 'sites/default/...
0
votes
1answer
29 views

File upload through form type file

My Drupal version is 8.6.10 I am trying to upload a file through the file_save_upload function and the function is looking for the file in Symfony\Component\HttpFoundation\FileBag Object $...
0
votes
2answers
52 views

$form_state->setRedirect not working after a $form_state->setResponse

In the submitForm of a custom form, I have this: $sFileName = 'sites/default/files/_private/bulletins/' . $form_state->getValue('adherent')[1] . ".pdf"; $response = new BinaryFileResponse($...
0
votes
0answers
19 views

How do I add a CAPTCHA inside a pop-up contact form?

Inside a pop-up form, I want add Recaptcha, I install Recaptcha module Drupal 8, $form['captcha'] = ['#type' => 'captcha', '#captcha_type' => 'recaptcha/reCAPTCHA',]; and in my twig ==> {{ ...
-1
votes
2answers
38 views

How do I get the value submitted for a form element?

I have a custom form for emails with the following form element. $form['type'] = array( '#title' => t('TYPE DE SOIN SOUHAITÉ'), '#type' => 'select', '#options' => array("Choisissez le ...
0
votes
0answers
16 views

tableselect default checked specific values

foreach ($courses as $user) { $options[$user['uid']] = array( 'coursecode' => $user['coursecode'], 'coursename' => $user['coursename'], ...
0
votes
1answer
35 views

Why isn't this Config API Code saving options?

I can see the form, using the Config API, and submit it. However, it doesn't save the changes. Here is my code: <?php namespace Drupal\my_config\Form; use Drupal\Core\Form\ConfigFormBase;...
0
votes
1answer
39 views

Avoid repetitive API calling in form rebuild while submitting

I am calling external API in form build function. While submitting form gets rebuild and call external API again. How can I avoid repetitive API calls in the form's build function? I used form_state-&...
0
votes
0answers
61 views

How to optimize select option Book outline of Book module

I'm using module Book of Drupal. It's so great. But I have a lot of books about 3000 books. When I create chapters for books that choose books very difficult because select option very large and ...
1
vote
4answers
309 views

How to to redirect a form to a certain node for anonymous users?

In a custom module, I have a form that is triggered by an option in a menu. I'd want this form to be redirected automatically (without action of the user) to a certain node (/node/2) when the user is ...
0
votes
0answers
17 views

Configuration translate Form Access Denied

This questions has repeat several times, but I face similar issues. Here are configuration yml information webform_protected_downloads.configsettings.yml token_text: 'test' langcode: en ...
0
votes
0answers
33 views

custom autocomplete not suggestion record after 3 characters

I created a custom autocomplete form in Drupal using hook_autocomplete. It works fine, when I type two characters. For example, a title is Newyork manhattan. If I type ne, it shows all the titles ...
0
votes
2answers
20 views

Start with multiple entity reference items

In Drupal 8, I have created an entity reference to an "author" taxonomy on a content type. The form display settings are set to autocomplete. By default it starts with one field and you can click "Add ...