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
23 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 \...
-3
votes
0answers
16 views

How to retrieve form data?

How to retrieve advanced search form data? I tried following but didn't work: \Drupal::formBuilder()->getForm()
0
votes
1answer
44 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
19 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
29 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
41 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
17 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
14 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....
-1
votes
0answers
35 views

How to ungroup address form elements

We're using the Address module to provide address functionality. But its widget is in a container ( details form element) But what we need instead that is to divide the elements, something like in ...
0
votes
1answer
63 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
27 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
votes
0answers
7 views

How do I integrate the recaptcha module in a contact form with ajax?

I have a contact form on the front page of my site, this form makes the sending of data with ajax, I incorporated the recaptcha but it does not work, any idea.
1
vote
1answer
19 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
42 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
24 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 $...
-2
votes
0answers
25 views

My site got hangup [closed]

I have a query on a website that usually has heavy traffic. Problem: Site got hangup two times with different errors. 2019-03-08T16:16:27.401498Z 0 [Warning] InnoDB: Table mysql/innodb_table_stats ...
0
votes
2answers
45 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
15 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 ==> {{ ...
-2
votes
0answers
18 views

hook_form_FORM_ID_alter() is not working [closed]

hook_form_alter() works fine but hook_form_FORM_ID_alter() doesn't. I created a hook to alter the action after the submission of a form. The hook gets called when hook_form_alter() is implemented, ...
0
votes
0answers
11 views

tableselect default checked specific values

foreach ($courses as $user) { $options[$user['uid']] = array( 'coursecode' => $user['coursecode'], 'coursename' => $user['coursename'], ...
0
votes
1answer
32 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
35 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
59 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
297 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
16 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
1answer
11 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 ...
0
votes
0answers
11 views

Update programmatically (js) the images of a image field in edit form

I have an entity type which has an image field. I use the default form widget for this, and I can upload or delete the image. On the node edit form, I have also a pop-up widget with a javascript app ...
0
votes
0answers
21 views

How do you add a field to a node type form?

I would like to add a boolean field to all node type forms and save it's value in config. I found this tutorial, but the code formatting is really bad. http://www.jaypan.com/tutorial/drupal-8-...
0
votes
0answers
17 views

How to keep a Form in a Block unique? [duplicate]

I have created a custom block containing a form. It works as long as there is only one block per page. But if there are more than one of these blocks, then the forms are not handled as unique forms. ...
0
votes
1answer
25 views

Drupal 7 chosen module use ajax to fill the select

I have two select elements and depending on what I select in the first select element second should fill from ajax call. First one is the simple select second one use chosen. The problem is if I fill ....
0
votes
1answer
26 views

How can I update the values of an exposed view filter when another filter changes value?

I know there are several examples of this around, on a view with two exposed select list filters, I need to update the value of the second based on the value selected on the first. I can't even seem ...
0
votes
1answer
26 views

Save paragraph widget data in custom form

I am adding a node field widget in a custom form as described here and my code is: $site_settings_node = Node::load($node_id); $entity_form_display = \Drupal::service('entity_type.manager')->...
-3
votes
0answers
27 views

How do I debug 404 page not found for custom route?

I developed a custom module, but I can't see the page it implements. I have installed and activated the module and rebuilt the cache as well. This is the code I am using. my_example_form.info.yml ...
0
votes
1answer
57 views

Custom user login in Facebook Auth modules

I try to run Facebook Login on my Drupal 8 site. I run it by Social API module and with Simple FB Connect, but both module generate user name from first and last name on Facebook. My user will not be ...
0
votes
1answer
89 views
+50

Redirect to a form with an array of Terms as a parameter of buildForm

Here is my use case: 1-I select few nodes from a view with VBO 2-I run a custom action on those nodes 3-As a result, this action create an array of Terms ($resultedTerms) My goal, after that, is ...
-1
votes
0answers
29 views

Commerce Ajax Add to Cart is not working on the first listing of every page

I am now using the using the Commerce Ajax Add to Cart 7.x-2.11 mod, which is going quite well, but the add to cart button for the first listing on any given listing page doesn’t respect the new ...
0
votes
1answer
24 views

Form API + AJAX - Form doubles itself on submit

I've been looking for an answer to this for hours now. A) No matter what I do, the form will always be visible again after submit. How can I stop the from from displaying after a successful submit? ...
-3
votes
1answer
27 views

How to modify contact form

I'm trying to modify the contact form to add a privacy clause before the "Send" button, I have to add a text and two mandatory check boxes. But I just started with and I have not much idea. Thanks.
0
votes
0answers
25 views

Can't get correct sequence and link to file in preprocess swiftmailer

I'm trying to pass Drupal 8 core Contact form data to a custom designed Swift Mailer template. The way I'm trying to do this is by getting all the fields dynamically to the template. function ...
0
votes
0answers
8 views

How to get user-submitted values in hook_field_widget_form after an invalid form sumbission

I'm trying to create a custom widget made up of a text field and a javascript map. When the map is clicked it adds a marker and updates the text field. If the user submits a form with this widget in ...
2
votes
2answers
47 views

How do I relocate the “Reset password” form?

Is there a way to hide and relocate the Reset password form from standard location? The login form needs to be shown as is. I wasn't able to do what the answer on How to print the local task bar ...
0
votes
2answers
36 views

how to implement Ajax callback on form_alter for entity field?

EDITED: I am able to display image for a field dropdown which have entity reference values to another content type. That is when a node content is edited or created. Note: I'm not creating form ...
3
votes
4answers
147 views

Multiple forms on the same page are causing conflicts?

I have the following code. function mymodule_get_node_create_or_edit_form($nodeType = '', $inputNode = null, $prepopulationFields = array()) { if (empty($inputNode)) { $values = array( ...
0
votes
0answers
21 views

How to set #default_value for radio button on Ajax Callback?

I've a form having a radios and 'select list with Ajax callback event'. When user changed selection from the select box, I tried to set the default_value for radio button. but it doesn't work. In the ...
0
votes
0answers
6 views

How to target daterange field in form alter?

I have a date range field in my exposed filter and I want to add a class on it. The problem is that I can't target it despite I can do it for the rest of the field of the form.How can I achieve that? ...
0
votes
1answer
36 views

form #type => checkboxes with zero / empty option value

I am building something which uses a form element with '#type' => 'checkboxes'. I want this to be reusable, so it should accept anything as option values that works as a PHP array key (integers ...
0
votes
0answers
12 views

Change form widget depending on role

I have a form open to public anonymous users. They can upload images to the private files directory. Only logged in users editors can see those images. When a new node is submitted by an anonymous, ...
1
vote
1answer
35 views

Check if user_picture value is changed or compare with old value

I am trying to find if a field value is changed or updated by the user. But there are blockers. function custom_form_process_user_picture(&$form, FormStateInterface &$form_state) { $...
0
votes
0answers
21 views

How to open modal on form button click with data from callback?

I have a form button with ajax callback: 'button_ajax' => array( '#type' => 'button', '#value' => t('Add short name'), '#attributes' => [ 'class' ...