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

I want to add a pagination below the Twig rendered table updating the Twig rendered table and the pagination form next and previous button links

What I Have: I want to consume an external API, and show the results on the page. For this I have created a custom route attached to the controller with a custom Twig theme. On visiting this route, ...
0
votes
0answers
6 views

AJAX altered Entityform edit form not rebuilt 2nd time

Background I have an Entityform (using module with 7.x-2.0-rc4) with two select dropdowns, and I'm trying to alter it such that the second dropdown filters based on the first using AJAX. Current ...
0
votes
0answers
5 views

Ajax submit comments by pressing enter

I am using the Ajax comments module and display suite. https://www.drupal.org/project/ajax_comments When pressing submit button the comment form gets submitted via ajax as it is supposed to. When I ...
0
votes
1answer
30 views

Control Visibility of Paragraph Without Fields

I'm preprocessing a paragraph to add a custom form but I'm having trouble with the visibility. I don't need any fields on this paragraph. If I just add the form to the paragraph the whole paragraph ...
0
votes
0answers
32 views

Can I set form field disabled in Controller?

I can make form field disabled with hook_form_alter. But can I somehow set form field disabled in Controller? namespace Drupal\mymodule\Controller; use Drupal\Core\Controller\...
0
votes
1answer
26 views

Impossible to html_entity_decode the button title in a render array

Here is the code that reside in my extended class of the RegisterForm: $title=$this->t("M'inscrire") // notice the apostrophe in French // the $element variable is the action sub array of the form ...
-4
votes
0answers
32 views

How to implement in drupal custom module [closed]

I am very new to drupal development. I want to create a Profile Page Which needs to show basic information as FirstName Last Name Email (Edit) John Michael ...
0
votes
1answer
31 views

How to embed HTML and CSS in a custom form element?

This worked in Drupal 7 but isn't in Drupal 8. $form['covid-19'] = array( '#markup' => '<div style="border: 2px solid red;padding:10px;margin-bottom:10px;"><strong>Due to the COVID-...
0
votes
1answer
22 views

How to save values on each form submit without overriding saved datas?

i am having a form with 2 values to save on submit: public function submitForm(array &$form, FormStateInterface $form_state) { if ($_POST['op'] == 'Import Accounts') { $filter = $...
0
votes
0answers
17 views

$form_state=>setErrorByName/setError on fieldset/container/etc

I have written a custom validation handler for webform that compares two fields. If the fields are in a container/fieldset/etc., I would like to set the error on the container instead of on the ...
0
votes
1answer
37 views

How can I set form values with Ajax?

I want to set the value of a textfield based upon the selection of a field above. You can choose a template and the textfield would have it as a value. This is the select field used to select the ...
0
votes
1answer
22 views

Form Select not rendering as a dropdown

I'm building a form that contains a select but it's not rendering as a dropdown. It's rendering with a scrollbar and a dropdown down arrow $form['my_select'] = [ '#type' => 'select', '#...
0
votes
1answer
36 views

How do I add the “onload” attribute to a script tag?

I need to add the onload event in jquery script tag as advagg does. I have done a bit of research, and I found that they are actually invoking hook_element_info_alter() and thereby add their ...
0
votes
1answer
53 views
+50

How to limit form submission per user per day and week?

The goal is very straightforward. I need a form to limit each user to 1 submission per day and 3 per week. What I found: Webform: The "Form settings" in webform has the "Per user submission limit" ...
0
votes
1answer
48 views

Extend a form from a custom module

I'm newbie with Drupal 8. I was entrusted with hanging a custom module to a Drupal 8 default login form. Together with these fields, I would like to see those of my form, which should be ...
0
votes
1answer
23 views

What's the best way to add an element to a form AFTER submission?

I have a form that I'm trying to build that is semantically identical to billions of others on the net: First GET request returns an empty form with no results displayed. Submitting the form POSTs ...
1
vote
1answer
18 views

Why do D7 form builders have a $form parameter?

In Drupal 7, the first parameter of a form builder function is $form. When implementing a form builder function, one has the option of either adding stuff to this existing array and returning it, or ...
0
votes
1answer
15 views

How to get bundle machine name when viewing the creation form?

From the creation form (any bundle), I need to get the content type label/name to use it in a link (in a block, for example) and pre-filter the View opened by this link. Example : The user wants to ...
0
votes
0answers
18 views

how to save field data on form submission programmatically in drupal 8?

I alter the form with hook_form_alter and created field in it. Now i want when i submit the form data/configuration stored in database of that field. how it will be possible below is the code. Thanks ...
-2
votes
0answers
15 views

How to process confirmations on form/webform data apllied from 1 user by multiple registered/unregistered people

I am really noob to Drupal and I am looking for some tips about how to process to process confirmations on form/webform data apllied from 1 user by multiple registered/unregistered people. I haven't ...
0
votes
0answers
25 views

Disable error on user login / register form

I've been trying to disable the error on top here : I have not been able to find the source of it. Doing messagesByType(TYPE_ERROR) does not return this error. I can see it within $_SESSION['...
0
votes
0answers
13 views

OpenModalDialogCommand in form not working

My form code is as follows. I am not able to figure out why the dialog box is not coming. This used to work before. The only change that I did was updated drupal to 8.8.2 version and it stopped ...
1
vote
1answer
32 views

How to populate an Entity Reference field from a modal AjaxResponse?

I have an entity ref autocomplete field (reference to bundle A) in one of my bundles (bundle B). I want to add a button below this field which will open a modal for a bundle A create form. This code ...
0
votes
0answers
22 views

Should I keep the '#theme_wrappers' => array() for form fields?

I am migrating a few custom modules from Drupal 7 to drupal 8 that contain a lot of forms built using the form api and contain fields like this one: $form['type_document'] = array( '#type' => '...
0
votes
1answer
38 views

how to pass a parameter to a route of type _entity_form

With some help I could create a route to an extended register form: as this form is an "entity form", my route have this type and the definition of this new form has been made in ...
0
votes
1answer
76 views

Route callback for RegisterForm results in Call to a member function getEntityTypeId() on null

My objective: Let say there is a role named "author". I would like to have a registration form having this path: /register/author, when the user submit, he/she will get the author role (same for any ...
0
votes
0answers
20 views

How do I reload an AJAX modal node add form without altering the behaviour of the original node add form?

I'm trying to edit the behaviour of node submit form (node type = 'class') but only when the form is submitted within an ajax modal window. Importantly, after the form in the modal window is submitted ...
0
votes
0answers
27 views

Custom webform validation handler not getting called using Event subscriber

I am trying to implement a custom validation for webform. I need to validate if user entered email is valid or not. For that I have altered the webform using event subscriber and assigned a validation ...
0
votes
1answer
32 views

How to set a new value in a paragraph field on submit?

In an edit form for a content with paragraphs, I set errors on the paragraph specific field with this particular syntax: $form_state->setErrorByName('field_paragraphs][' . $key . '][subform][...
-1
votes
0answers
47 views

Ajax submit form data to controller and update content in twig template

EDIT: My first code example had some faults.. I believe that I now have a module of a working non Ajax Form. - Any help pointing me in the right direction to submit and update the output with ajax is ...
1
vote
0answers
16 views

Ajax callback not called from a modal form

I dont understand because after i opened a modal form in drupal using this method (inside class Announcements) public function ajaxSubmitForm(array &$form, FormStateInterface $form_state) { ...
0
votes
1answer
27 views

Returning from ajax callback ruins view

Currently I am hooking into the add to cart form on my website. I added ajax to the edit quantity buttons like : $form_quantity[$key]['#ajax'] = [ 'callback' => 'update_cart_order', ...
0
votes
0answers
17 views

How to disable “Tampering rejected … An attempt to update the title of node…”

I write a code to change the node's title after the form is created, but it always says Tampering rejected ... An attempt to update the title of node with ID "42154" was discovered (from "9-2" to "...
0
votes
2answers
47 views

Creating a route with a form and some content

i have created a route with a form: amu_404_redirect_import.admin: path: '/admin/config/amu_404_redirect_import/upload' defaults: _form: '\Drupal\amu_404_redirect_import\Form\...
0
votes
2answers
40 views

Storing ajax callback variables in PrivateTempStore

I have an issue with changing / obtaining variables in form element's ajax callback function. (Sorry for typos, I just placed a pieces of whole code). I have form with input field, where user can ...
0
votes
2answers
74 views

How can I create a GET form with the Form API?

I have been struggling with the Drupal 8 Form API all afternoon. It seems that the API is not meant to create GET forms, while the comments state otherwise. I am trying to build sort of a filter-form ...
0
votes
1answer
51 views

Ajax Multiple Callbacks is not working for first callback?

I have been trying to load the data to other select list field from the first select list callback. I want to change the two select list variables based on the first select list on changes, please ...
0
votes
0answers
16 views

managed_file FormElement submitting form upon file upload

How do i prevent managed_file(Browse Button) from calling submitForm function upon uploading file? I've added '#attributes' => [ 'submit' => FALSE, 'onclick' => 'return false' ] to no ...
-2
votes
1answer
24 views

For Each, set element's title to some string

Hi I have made a custom module to alter the address module form. It works well for one field, however I am stuck trying to use a for each loop in recursively calling this to as many elements there are....
0
votes
1answer
34 views

Problems with altering a form [duplicate]

I'm wanting to alter the commerce cart page form. By using var_dump($form_id) or chrome inspect I can see the id is id="views-form-commerce-cart-form-orange-default-42". If I write my hook as : ...
0
votes
0answers
12 views

Upload two images in ckeditor, a desktop and another responsive version, is it possible?

It will be possible to add two images in the image dialog form, the idea is that the user can upload a desktop image and a different one. Could someone help me ?, is there a module that does this ?, ...
0
votes
0answers
8 views

Image inserted into Ckeditor via Media widget exists when viewing config storage in custom form but not outside of custom form. Example below

I have a custom form like: public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config(static::SETTINGS); // dpm(check_markup($config->get('...
0
votes
0answers
9 views

How to stop a custom form from being submitted twice simultaneously

We have an issue with a custom form's validation/submit steps being processed twice, resulting in unexpected behavior. This form creates an object with some unique fields, therefore, when the second ...
1
vote
0answers
40 views

Increment form field value by one on submit form with Ajax cal

I have my custom form: class MyCustomForm extends FormBase{ /** * {@inheritdoc} */ public function getFormId() { return 'my_custom_form'; } public function buildForm(array $form, ...
0
votes
1answer
33 views

Delete confirmation as popup

I have a view containing saved user webform drafts set up in a table format. I have given permission to the authenticated user to delete own submissions. When clicking the delete link located on the ...
0
votes
0answers
25 views

Ctools wizard for user registration (with entity creation)

I am rebuilding a Drupal 7 site in Drupal 8. The original site had a ctools wizard registration, where step one was the standard registration form, step two was a node create page, and step three was ...
0
votes
1answer
17 views

Add hook form alter to create a list from MySql database in Drupal 8

I am creating a Drupal 8 form using custom content type. One of the fields to be created is a select list. The data that will be on the select list is stored in a MySQL database which needs to be ...
0
votes
1answer
63 views

Can we pass argument to a form from a Twig template

I have a form that accepts a custom argument sourceid public function buildForm(array $form, FormStateInterface $form_state, $sourceid = NULL) Now, this form is displayed in a twig template ...
4
votes
1answer
51 views

How do I retain user input in a form after submission?

I am working on a simple form for searching a collection of marriage licenses. It consists of a select box where the user may choose to search last names, first names, or both, and a text field where ...
0
votes
0answers
8 views

Move field into the Menu settings on node edit

I want to move a field into the "Menu settings" section in the sidebar on node edit form page with the following code: /** * Implements hook_form_alter(). */ function mymodule_form_alter(&$form,...

1
2 3 4 5
128