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.

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
21 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
40 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
34 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
56 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
86 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
28 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
51 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
61 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
32 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
36 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
78 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
41 views

Ajax dependent drop down not working on form rebuild

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
37 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
70 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
1answer
67 views

$form_state->setRedirect not working after a $form_state->setResponse [duplicate]

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
22 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
39 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
17 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
317 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
18 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 ...
0
votes
0answers
13 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
24 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
41 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
31 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
28 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')->...
0
votes
1answer
71 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 ...
-1
votes
1answer
110 views

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 ...
0
votes
1answer
25 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
34 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
10 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
103 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
59 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
164 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
53 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
9 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
56 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
49 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
22 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' ...
0
votes
0answers
25 views

Prepopulate additional instances of a multivalue text field based on another existing text field?

Consider the following (newly created) form: field_country (option select) field_phonenumber number (multivalue text field) When the user chooses from field_country, then the user can add unlimited ...