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
2
votes
0answers
8 views

Entity Validation API not invoked on saving the taxonomy overview form – misunderstanding or a bug?

I have a Constraint and ContraintValidator to validate a field of taxonomy terms. Its a hierarchical taxonomy called channel with a field field_product. It's required that a channel has the same ...
0
votes
0answers
33 views

When doing a page preprocess, how do you know if the page is a form?

When doing a preprocess on a page (I need to conditionally change something at the page template level) is there a way to tell if the page is going to render a form? The xdebug output didn't show any ...
0
votes
0answers
23 views

I want to use dd/mm/yy as date format in a custom form instead of default mm/dd/yy

I am using the following date form element. $form['dobnew'] = [ '#type' => 'date', '#title' => t('Birth Date new'), '#date_date_format' => 'd/m/Y', '#default_value' => date('d/m/Y')...
-1
votes
0answers
35 views

Node variables in form twig template

{{ form }} is the only available variable in form.html.twig template file How can I access raw values from node fields in a twig template? I'm going to use hook_preprocess_node_edit_form for creating ...
-2
votes
1answer
19 views

Form APi Could not parse property path Unexpected token

Using Drupal 9.1.4 symfony/property-access I think is on 5.2.0 [that's the last version mentioned in the changelog] I have a custom built form with some date and number fields, for example: $form['...
2
votes
2answers
45 views

How to create a new parent section on the Configuration page?

When one navigates to Manage » Configuration, the page is divided into sections which (in the "Seven" theme at least) shows up in individual boxes. These sections have headings like "...
0
votes
0answers
8 views

How to add “clone” button to WebformMultiple field

I created a custom composite field with a dozen or so fields, in a custom module extending Drupal\webform\Element\WebformCompositeBase. I need to add a "clone" button to the webform multiple ...
-2
votes
1answer
65 views

How to add and associate Paragraphs to Media Library Images Programmatically

Good day everyone, Our client wants to have this feature where he can upload/reuse multiple images for an article content type. This can be achieved using a Media Library, where I find it tricky is ...
1
vote
1answer
40 views

Ajax enabled form stopped working - Ajax callback never called

I have the weird problem that an Ajax enabled form that just worked stopped working - and I have not a clue what is causing this and when it stopped to work. The form itself has no changes for months ...
0
votes
0answers
20 views

Replace Block on click of form element

I have a block which contains a form (I used the build() method) . One of the form elements has a suffix as follows: $form['test'] = array( '#type' => 'number', '#placeholder' => t(...
0
votes
0answers
8 views

Autofocus on select or textfield works on and off

I have set autofocus on my form element as follows: $form['product']['widget']['#attributes']['autofocus'] = TRUE; The element is autofocused intermittently, if I refresh page 10 times it works for ...
0
votes
0answers
25 views

Delete an account without showing the confirmation form

I've been working on creating a feature which allows certain non-admin but higher-than-user roles within a Drupal 8.8 system to delete users from the system. In essence, only admin and 'moderator' ...
1
vote
1answer
34 views

Is there any way to show a “computed field” value in edit mode?

I have a content type (Structure) to which I added a text computed field. In a module I added the following code. function computed_field_field_reference_compute($entity_type_manager, $node, $fields, $...
1
vote
1answer
36 views

How do I download a form table in CSV or Excel format? [closed]

I have a form whose class extends FormBase. The form has a table that gets populated with information. Basically I'm trying to download the table into a CSV or Excel file. I've seen some old posts for ...
1
vote
1answer
27 views

How to add template suggestions for form elements of a certain form ID?

I'm looking to edit some Twig templates for certain form elements, but I need template suggestions only for certain form IDs. How do I go about that? I currently have the following functions in my ....
0
votes
0answers
10 views

Show field conditionally + display each form part in div

I've followed the tutorial in order to create field conditionnaly, but the field is always shown. This is possibly due to the way I'm calling my form ? And if I do as I did in my template, how can I ...
1
vote
1answer
19 views

How can I alter the form to add a new validation handler?

I'm on Drupal 8. I have created a new media bundle (permissions_json) which can be created from /media/add/permissions_json, where administrator user can upload specifically formatted JSON files, and ...
0
votes
1answer
52 views

Inline Javascript throws an error on drupal_add_js() within an AJAX callback

I am trying to get JavaScript to measure a text field and auto submit at a character limit for an Ajax callback to be validated against a Luhn Algorithm and errors out on failure to validate. I found ...
2
votes
2answers
103 views

How to expand NodeForm so new argument can passed to it

I have a content type called service request, which have some conditional fields that each might appear or disappear based on an other field value called service type. I have used conditional field ...
0
votes
1answer
18 views

How to add a button in the header of a table form?

I have this table form: The corresponding code for the header is $form['inscriptions'] = [ '#type' => 'table', '#header' => [ [ 'data' => '', 'colspan' => 2, ]...
0
votes
1answer
34 views

States don't work for a block rendering a form

I created a block in which I called a form inside the build() function. The form class has elements like radio button, input field type number, and submit button. I added a state condition to make the ...
0
votes
0answers
26 views

How add a paragraph field to a form programmatically?

I'm on Drupal 9. I am creating a custom block programmatically with some fields in the configuration form. However, I need to add a paragraph field and I've found no documentation\working way to do so....
0
votes
0answers
20 views

Form doesn't update via hook in edit mode, instead of it page reloading

This is not happening all time (possibly for big amount of existing field, I'm not sure, with less amount of fields form is saving as it should) when I'm adding new Field collection entity or update ...
0
votes
0answers
11 views

Add State visible on tableselect

I try to add state "visible" on tableselect in a drupal 8 form public function buildForm(array $form, FormStateInterface $form_state) { $form['monselect'] = [ '#type' => 'select', '#...
0
votes
1answer
23 views

Conditional form states in hook_form_alter()

I have a node with a field, whose widget uses select boxes and multiple choices are possible. The values are coming from a taxonomy entity reference field. There is another field, a text field, which ...
0
votes
1answer
29 views

How do I alter a form submission handler?

I want to alter the form submission handler submit for the search block with a custom module. Setting $form['#attributes']['class'] works, but the submission handler doesn't seem to be triggered with ...
0
votes
1answer
19 views

Form type markup states

Is it possible to create a form element of type markup and add a state to it, to make it visible on a condition? I can't seem to make it work and get the error: Warning: Undefined array key "#...
1
vote
1answer
38 views

How can I upload and read an unmanaged file?

On a custom form I have a file field. Having chosen the file and clicked Submit, I'm trying to find how to access and read the uploaded file. I have no need to move or save it, I simply need to open ...
0
votes
0answers
12 views

How to set multiple default values in cshs field using form alter?

I am using cshs widget on my taxonomy entity reference field. The taxonomy entity reference field can accept unlimited values. I want to set the default value for this field using form alter based on ...
1
vote
2answers
21 views

Unset email address requirement on User Form not taking

The scope of our project doesn't require users to have an email (they can use phone instead), therefore, I'm trying to unset the email requirement like so: function my_module_form_user_form_alter(&...
0
votes
1answer
41 views

Can you save state in the $form_state variable that remains when the form is rebuilt?

I have a form with a nested subform that has an ajax submit button in it. The subform is built inside a form_alter and attached to the form. The submit buttons #name is made unique by using a UUID ...
0
votes
0answers
18 views

Form ID value changes, breaking the action link

I have a custom module creating a form. As the form is a bit down the page, I have added an anchor to the submit so the user sees the results without the need to scroll down public function ...
0
votes
0answers
21 views

Custom form returns NULL in custom template

I have: A custom form A custom theme A custom module for this form I am trying to get the custom form to display on a custom template which is in a custom theme. The directory structure for the ...
0
votes
1answer
63 views

Get image file values in $form_state in media entity form

I am trying to get the values from an uploaded image inside a media entity during form submit. Where my approach doesn't work: When first uploading an image in the media_image_add_form form. When ...
0
votes
0answers
31 views

Adding an icon in a form item element

I have a form where we are displaying a static text like: Please select the <icon> button to view X Where the icon is a an image. I've added this piece to the form by doing the following: $form[...
0
votes
1answer
19 views

Views filter with additional form element

I have a custom views filter extending Drupal\user\Plugin\views\filter\Name that I am trying to add an additional form element to. The existing filter is an autocomplete field that I need to add a ...
0
votes
1answer
23 views

How can I render form elements?

In Drupal 6, I am using the following code. $rows[] = array( array('data' => drupal_render($form['collected'])), array( 'data'=> drupal_render($form['count']) . drupal_render($form['...
0
votes
1answer
55 views

Multiple forms on one page

I try to input several forms into one page via Controller. With code which is under, I see those forms but after submit one of them, nothing happens. Any of data is send to database. Has anyone idea ...
0
votes
1answer
63 views

How to automatically add http prefix to links in a form?

I am trying to come up with a solution to fix the D8 Link module to allow URLs like example.com (the most common use case, imho). I was thinking it would be simple enough to modify the submit value ...
0
votes
0answers
25 views

How to prevent image/file deletion from a configForm if don't press on submit button?

I created a custom config Form in drupal 8, and this form have a managed_file field for upload a logo, the problem is that i set all fields, upload my image and fill other fields, press save, and in ...
0
votes
0answers
14 views

Adding a button to a table form

I am trying to create a configuration page for my module that lists a set of php scripts that admins can use to trigger off different scripts. To do this, the configuration page is a form that has a ...
0
votes
1answer
16 views

Can we alter a form using view data?

I is possible to: Hook on views_pre_view (which is executed before form_alter) Query view data (execute the view query filtering according to URL parameters) and collect some data Hook on form_alter ...
0
votes
1answer
40 views

How can I reference an entity field in a template file?

I am trying to theme the node add/edit form for a custom content type (for example, Album). I implemented hook_form_alter() in the theme. function mytheme_form_alter(&$form, \Drupal\Core\Form\...
0
votes
0answers
19 views

Find the object of a field widget on a form

I have two fields on a form. One is a select list with an Ajax callback on 'change'. When I am in callback, I want to call a function (addMoreAjax) on the second widget. For that I need to find the ...
0
votes
0answers
16 views

Firing custom submit on ajax form works with #ajax_processed set, but reloads the page

I'm placing a subform within the node edit form using a form_alter where I build the subform and add it to the form array. My subform has a custom submit handler and '#ajax' is set: $form['...
0
votes
0answers
23 views

Form submissions including HTML in email notifications

I have a website where the core contact form is submitting the form markup along with the content. So for example, this is in the email notifying the site owner of the submission: <div class="...
0
votes
0answers
24 views

FormState object gets no values from embedded form placed with AJAX

I have a form which is added to a node edit form via AJAX; a controller builds it, renders it, and sends it back to the node edit with the following code. $rendered = \Drupal::service('renderer')->...
0
votes
1answer
29 views

How to get the row added by ajax in the right place?

I have a table form created from a custom entity: public function buildForm(array $form, FormStateInterface $form_state, $contract = NULL) { $form['subscriptions'] = [ '#type' =&...
0
votes
0answers
10 views

How to move the Entity Browser “Create Entities” button below the created/selected entities

Drupal 8 / Entity Browser Module When leveraging the Entity Browser form field display, the "Button" is always displayed on top of the created/selected entities, like so... I'd like to move ...
0
votes
1answer
22 views

Send mail to author of content

I use Drupal 9.1.4., core Contact module, Contact email module and Contact storage module. How to use the author as a referenced entity to send email to author of content (in this case autor of ...

1
2 3 4 5
132