Questions tagged [forms]
Use it for questions about the Form API. Don't use it for entity or entity field forms.
6,769
questions
-2
votes
0
answers
25
views
Using form to create a price calculator [closed]
I want to create a module that will calculate to total price of the computer components selected by the user. It consists of some predefined checkboxes of item names and submitting it would show the ...
0
votes
1
answer
36
views
When a custom form is displayed in a custom template, ajax does not work
What I want to do
I want to display a custom form with a custom template and use ajax in it to change values in the form.
Problem
Custom template notation prevents ajax from working.
I didn't change ...
0
votes
1
answer
22
views
Form field states with media fields that use media library widget and conditionally displaying visibility based on other media fields
I am trying to get some media fields to hide/show conditionally using $form fields #states API, based on other media fields (all the media fields are using the "Media Library" widget in form ...
0
votes
0
answers
20
views
Html5 tags and javascript stripped out form radio labels
On D7, I have the following simplified code
function mymodule_multistep_form($form, &$form_state, $vars) {
$mystatictext = get_my_static_text($vars);
$options ='<div class="...
0
votes
0
answers
24
views
not able to use logger in a class /closed
I have a quick question. (drupal 9)
I'm working inside a custom form class (custom_module/src/Form), in a public function.
I want to log some values so I can debug, but the default Drupal logger is ...
0
votes
0
answers
12
views
How to set media field mappings to autofill the target fields when uploading the file instead of saving to those files when saving the media entity
I am using the document media type for pdfs. I am also utilizing the field mappings for:
Name
MIME Type
File size
and I will be adding a field mapping for the pdfs subject as well using a Media ...
1
vote
1
answer
41
views
Storing temporary data in a form AJAX callback
I have a form submit button that when clicked fires an AJAX callback.
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Title...'),
'#ajax' => [
'callback'...
0
votes
1
answer
41
views
Check in buildForm method of custom form class if the form was submitted
I have created a large form with a class extending FormBase. Many of the elements rendered within the form are only necessary for the user to see - there are not so many really relevant fields in the ...
0
votes
1
answer
52
views
Block Configuration Form Returning Unexpected Value
I'm trying to build a block configuration form. Here's my blockForm code:
public function blockForm($form, FormStateInterface $form_state) {
$form['resolve_ip_addresses'] = [
'#type' => ...
1
vote
0
answers
23
views
Focus Returns to Field With AJAX Callback [duplicate]
I am attempting to complete several AJAX commands based on the value of a field in a node/add form. The commands themselves work. However,when a user is filling out the form the cursor (focus) keeps ...
-1
votes
1
answer
33
views
How to remove author field from the 'advanced' field group on the node edit form
I've got several node edit forms that, in most themes, display the 'advanced' group in a sidebar. I have other plans for the sidebar, though, so I don't want that behavior.
I edited some twig and css ...
0
votes
1
answer
33
views
How to check for content type in hook_form_alter
I see from the api and various posts that I can identify a specific form to change using hook_form_alter, like this: hook_form_FORM_ID_alter()
From experience, I know this can be done in the .theme ...
0
votes
0
answers
14
views
Custom widget with entity reference and another field - not saving
I'm trying to create a custom field for my entity (entity A). It will hold custom entity reference, let's say entity B, with another field associated (integer).
I want to create associations entity A -...
0
votes
0
answers
16
views
Form tries to process submit field as entity property
I want to create a simple admin CRUD form. I am using the default form.
class TestForm extends EntityForm {
public function form(array $form, FormStateInterface $form_state) {
$entity = $this-&...
0
votes
0
answers
22
views
Trying to create a cell when using tables in forms
In one of my custom Drupal modules I'm trying to crate a form that also contains a table. One of the table sections looks like the following:
$form['consumption_' . $week]['mood']['title'] = array(
'...
0
votes
1
answer
39
views
Run custom php code or file in drupal content type form submission
I have this drupal site, there is a candidate registration page where anyone can fill the details (name, gender, address, mobile no etc) and submits and a success node page is displayed with all ...
0
votes
1
answer
42
views
Dynamically generate Form API select list of routes to page displays of a known View
Given a known View, how would one dynamically generate a Form API select list of the routes to its Page Displays?
In my case, I have a Search API View (view.search) with a default site-wide search ...
0
votes
1
answer
54
views
Why does this code to create a dependent dropdown not work?
I am trying to implement the dependent dropdown option in Drupal 7 from this URL http://w3shaman.com/article/creating-ajax-dropdown-drupal-7. When changing the first dropdown value, it is showing the ...
1
vote
1
answer
60
views
Form builder not getting checkbox values
I cannot determine why the form state seems to fail to get the values of the checkboxes on a form I'm building.
In my buildForm(), after submission, I am returning a result set. Each result that is ...
0
votes
0
answers
23
views
Twig template for field component of specific form [duplicate]
I'm using template hints to attempt to theme a specific part of a single form.
I have a custom template for a views block (block--views-exposed-filter-block--search-custom-page-1.html.twig), but is it ...
0
votes
1
answer
49
views
AJAX on Form Details
I have a lot of API calls in a form, so in order to not call everything on load, I only want to load it when the user opens the details element.
But I am having trouble adding #ajax to the element. I ...
0
votes
1
answer
75
views
Dynamicaly add ajax form item and add event on checkbox
I've added an ajax callback to my form to add some data on it :
$form['add'] = [
'#type' => 'button',
'#value' => t('add'),
'#ajax' => [
'callback' => [$this, '...
0
votes
0
answers
78
views
How can I Speed up Cache calls?
I have a site with a few complicated forms. They require a lot of CPU time to calculate, so I am caching the $form array in order to be able to deliver the form quickly to the user. To do this, I am ...
0
votes
0
answers
37
views
interaction between form element plugins and config entity plugin collections
I'm making a form element plugin which has compound elements, but which should return a single string value. This is the same idea as core's password confirm form element (https://api.drupal.org/api/...
0
votes
0
answers
13
views
How to prevent modal boxes for Drupal 7 edit forms
I am very annoyed by the modal boxes showing up for most edit functions in Drupal. For example, when editing a php field code, only a few lines are displayed, I must copy the content in an other ...
1
vote
1
answer
52
views
Problem with Adding new fields with Ajax call to a custom form
I have a simple form where I am trying to add a couple of fields to it when the user clicks a button using an ajax callback. Here is what I have:
public function buildForm($form, FormStateInterface $...
1
vote
0
answers
46
views
Trying to insert a line break inside a table header array
So I'm programming a module in Drupal that contains several custom forms, one of which also has a table.
One section of the code of the table mentioned above looks like this:
$form['completion_' . $...
0
votes
0
answers
23
views
How to access block contents in run within hook_form_alter? [duplicate]
I am using Drupal 9 and I need to get the block content within hook_form_alter implementation, I tried these lines:
$bid = 'consumerorganizationselection';
$block = \Drupal::entityTypeManager()->...
2
votes
1
answer
66
views
How can you cache a form render array?
I have a custom module which builds a set of complicated forms, and these forms are built dynamically (the option lists for certain SELECT items, for example, are fetched via an API call). Some of ...
1
vote
1
answer
86
views
Is there a way to add / remove items from an unlimited cardinality field in form alter / after build?
In a node edit form, I am trying to add items to a multivalue field with unlimited cardinality in a form builder hook, like form_alter or after_build. I can't figure out how to do it, though, at least ...
1
vote
0
answers
59
views
Why the form does not save data from the entity reference field?
I have a custom entity (with the name Entity Quote), from the add form of this entity I make a multistep form.
In the custom entity Entity Quote, I added another custom entity (with the name Quote ...
0
votes
2
answers
41
views
Change default value when triggering form #states
By default, my field_taxo has the value 'castle'.
_none
castle (by default)
mansion
The field_taxo is only showing when the role 'marketing' is checked, and becomes required.
/**
* Implements ...
2
votes
1
answer
25
views
How can I populate radio options on a form with user entities?
I have some user entities and I want to make them available as options to choose in a radio button element on a form.
I can populate the options with a username no problem, so visually I can achieve ...
-2
votes
1
answer
251
views
Serialization of 'Closure' is not allowed in serialize()
i am in the midst of fixing our website (which is built using Drupal version 7.67) that shows many errors after the PHP version is updated into PHP 8.0.
One of the errors that i am stuck now is this ...
0
votes
1
answer
41
views
Node form field validations on change with AJAX
I'd like to be able to trigger the validations for a field, including relevant entity constraints, on a change (or equivalent) event for the field using AJAX. But I cannot figure out how to make that ...
0
votes
1
answer
34
views
How to programatically publish content after form validation
I have a content type of which its status is set to unpublished and is disabled.
A site manager needs to publish the content after approval.
The site manager wants to skip this validation process when ...
1
vote
1
answer
87
views
Hiding machine name from a form temporarily only during validation
I’m looking for a solution to hide machine_name from a form temporarily (only during validation) and restore it afterward.
When the form has validation with errors the machine name appears (with a ...
0
votes
2
answers
269
views
How to set widget for a field on a custom form?
How do I set the widget to be used for a field on a custom form?
I am surprised I haven't been able to find something covering this. Sort of expected it to be something like:
$form['interest'] = [
'#...
0
votes
2
answers
52
views
Remove settings no-longer present in custom modules config form from drupalSettings
Hello Drupal Code Land,
I have created a custom admin form in a custom module as a class extending ConfigFormBase. I use this form as an admin config form to set pricing options for different ...
1
vote
1
answer
101
views
How to programmatically set a checkbox value of an user account which field is not in /people/accounts/fields
I need to set a checkbox which has an unknown field (machine) name in the user account. the checkboxes are in the user account /user/?/edit
but they doesn't appear as fields in people/accounts/fields ...
0
votes
1
answer
72
views
submitForm not being called when put inside a Custom Block
I have been trying to find a fix for this but I haven't been able to. I have tried to put a form inside a custom block to render the form as a component. When the form is submitted it renders the ...
0
votes
1
answer
41
views
How to fetch form values for Simple hierarchical select?
I have referenced a field with taxonomy by using simple hierarchical module and now I have to fetch the options programmatically to perform some actions on them.
I tried to fetch it like the below it ...
0
votes
1
answer
29
views
Why does adding #element_validate give warning about invalid callback?
I have code that adds #element_validate to all fields of a certain type (Link fields).
$form[$field_name]['widget'][0]['#element_validate'][] = '_fix_link_field_value';
array_unshift($form[$field_name]...
0
votes
1
answer
87
views
Generating forms dynamically from json data [closed]
I have a large set of JSON data which I need to process somehow into forms for users to interact with, fill in data and submit.
However, there are far too many to create all the forms by hand and I ...
0
votes
0
answers
29
views
How to target buttons to add a new paragraph field
In a form_alter hook I'm trying to target the buttons to add a new paragraph but can't seem to target the specific buttons. The buttons are multiple entity references with unlimited cardinality, but ...
1
vote
1
answer
59
views
Redirect user to a custom page after one time login
If my user click to "forgot password", and email with a one-time login is sended.
When the user clicks the given link, he's redirected to this page /user/reset/$id with the user_pass_reset ...
0
votes
1
answer
37
views
How To Resolve Commerce Button Returning Error?
I'm using the latest stable version of Drupal Commerce (on Drupal 9), with every module up to date
Problem: When the add to cart button is clicked the site returns message "The website ...
0
votes
0
answers
41
views
Callback Not Firing On Change
I am somewhat new to Drupal development. Please bear with me on this.
I am trying to create a popup after a user enters a value in a date field on a node/add form. This is on a Drupal 9 site. To do ...
0
votes
0
answers
78
views
#limit_validation_errors not working for reset button?
I have a page view with some exposed filters (i.e. main content page). Some exposed filters are auto-complete fields (i.e. user references). So if I type some rubbish for user name and submit form I ...
0
votes
0
answers
26
views
Entity queue: Can I use entity browser for selection but keep a draggable table for re-ordering?
On a Drupal 9 site we have an entity queue. We would like to use a draggable table for re-ordering but when the editor clicks "Select entities" they would like to use a modal entity browser ...