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

Dynamic Radio options return An illegal choice has been detected. Please contact the site administrator

I am using Drupal Commerce 2 and have created a CheckoutPaneBase for shipping methods that we get from an internal service. I am not using Ajax and when the user adds their shipping address, they go ...
-2
votes
0answers
23 views

How do I show node content of previous node during node creation?

Let's say, we want to collect data on a regular base in a Drupal installation. On recurring events in the real world, we want to add a new set of data. So far, I think it should be easy to create a ...
-2
votes
0answers
31 views

retrieve existing form

I designed a form by using drupal UI, and I want to develop some code to precisely manage it (add some fields, hide some others, define values, ...). I studied a number of answers on this forum, but I ...
0
votes
1answer
20 views

How to set role on the registration form programmatically

I'm trying to create multiple registration forms with a role assigned to each. It seems that my default value for the role is not keeped, but it works with other fields Here is my code $form = $this-&...
0
votes
1answer
35 views

Is it possible to call a custom ajax event after removing a file from a managed_file field?

I have a custom form with a managed_file field element. I'd like to call an ajax event after removing a file (clicking the REMOVE button). Is there a way to expand the existing ajax callback for the ...
0
votes
0answers
17 views

How can I conditionally override the field description?

I am using the Reference Field Option Limit module in Drupal 7 and I want to change the explanation text that says: No options are available for the current form values.. I want to put instead: ...
0
votes
0answers
36 views

How can I set a custom form's element after a managed_file ajax callback?

Scenario: I have a custom form whose first step is to upload a file using a managed_file field element. Then, after this manged file is uploaded I want to rebuild the form using information from the ...
0
votes
1answer
34 views

Some #states not working for custom field but do work on identical webform field

I'm working on a project where I'm programmatically cherry picking elements from a webform and then creating a custom form with all sorts of alterations and additions to the "cloned" webform ...
0
votes
1answer
23 views

Is it possible to return a form element AND an ajax response from the same ajax callback function?

I have an ajax callback function that needs to return a form element and also an ajax response. Is it possible to do both? In my callback I need to set and return something like: $form['fid'] = array( ...
0
votes
0answers
30 views

How can I set a field's #value in a custom Form AJAX function?

I have a managed_file field type that has its own build-in #ajax command and I need to add an additional custom command that will populate a hidden field on the form. So far I have a custom managed ...
0
votes
0answers
23 views

Modify form (add select option) by another form in Modal

I wonder if Drupal can add an additional segment of data in a form on the fly using another form via Modal. I have this form in a table. City | Description | Active New york | ...
-1
votes
1answer
48 views

How to let the user fill in the “Recipient” field of the contact form?

I created a new type of contact form. It is called "Invitation". The problem is that the recipient field does not appear and it is not editable. I want the user to fill in the recipient's ...
0
votes
1answer
16 views

How to check if managed_file has uploaded a video and use it in states

I want to disable the submit button in a form for as long as there are no value/uploaded video in a managed_file but I can't seem to find what form name or element property I have to check for in #...
2
votes
1answer
48 views

#ajax on a managed_file custom form field is not working

I have a custom Drupal 8 form using a managed_file field with an #ajax callback but the ajax callback is never called (example below). I assume that it's because the managed file field type is already ...
0
votes
1answer
31 views

How can a description be added to the body field summary widget in node edit form?

On a particular content type I have made summary input required by checking both "Summary Input" and "Summary required" on the body field settings. We would like to add a help text ...
-1
votes
1answer
46 views

How to check if dynamic select query returns zero records and return markup

I have a custom Drupal form that is populated with a dynamic query. How do I return an 'alert' if no results are returned? There has to be a better way of doing this than what I have come up with. ...
0
votes
1answer
25 views

Target EntityBrowser in custom validation constraint

Having a custom validation constraint on an entity reference field using entity browser as form widget, I am trying to get the field light up in the form on validation violation. This is not working ...
0
votes
1answer
22 views

How can we make the summary field auto expand on load?

We have an admin page with a summary and body. The summary is auto collapsed but we want it to be automatically expanded on the page load like below in the image.
0
votes
0answers
29 views

Error displaying block created progamatically

I am trying to create a block with a form to display inside the block. Here is my block <?php namespace Drupal\fixx_helper\Plugin\Block; use Drupal\Core\Access\AccessResult; use Drupal\Core\Block\...
-3
votes
0answers
47 views

How to automatically flag an entity when the form is submitted?

I created a small custom module in Drupal 8 to moderate new entities and update entities. The module is simple. It marks with the help of the flag module, the entities created or updated automatically....
0
votes
1answer
25 views

Is there a browser-side validation passed event I can listen for?

Is there a JS event that my own custom code can listen for to determine that client-side / browser validation of a form has passed? i.e. That no messages like this have occurred: "Please fill in ...
1
vote
1answer
53 views

Ajax form add library on callback

I'm having an AJAX form, which on submit fires a callback function where I want to attach my library. Here's the submit button: $form['actions']['submit'] = [ '#type' => 'submit', '#value' =...
1
vote
1answer
37 views

In hook_form_alter(), how can I access the entity that is being flagged?

In hook_form_alter(), I want to load the entity being flagged so that I can do some processing based on the field values of that entity. However, I can't find an entity object using kint($form). I ...
1
vote
1answer
127 views

Better code to output a pdf downloaded by the browser

In a submit function of a custom form, I would like to output a pdf which can be downloaded by the user/browser when clicking on 'Get PDF'. The following code is doing the job only once, because after ...
3
votes
1answer
40 views

Redirect to a specific tab in a page after node submit

I'm working on Drupal 8.9.6. I'm trying to redirect users to a particular page after they add a node. I can do that without any problem, by adding the following information in the form's URL: /node/...
0
votes
1answer
57 views

Autocomplete field where title is replaced with NID

I'm using Drupal 7 and I have made autocomplete function to be called on a field. File my_module.module: <?php function my_module_menu() { $items = array(); $items['/...
0
votes
0answers
26 views

How can you add a tab programmatically in Manage Form Display for a block

The hook: hook_enitity_base_field_info() and BasedFieldDefinitions allows you to create fields for all the custom blocks. Those fields are then used in Manage Form Display. I want to add a field group ...
-3
votes
2answers
68 views

Split custom form into multiple smaller functions for re usability [closed]

I've a created a custom form in custom module. I have couple fields in the form that can be reused to other form.Also as per the coding standards, the function should not be more than 150 lines. So I ...
0
votes
0answers
39 views

If I have 2 same name taxonomy term which is used with nodes. how to set only one instead of both?

I have 2 taxonomy terms with the same name (knight(2) and knight(6)) in my Drupal 8 Project; both terms have been used with nodes. I want to replace knight(6) with knight(2) in all the nodes. I ...
0
votes
0answers
19 views

Autocomplete submit on selection of suggestion

How to make an autocomplete submit on selection of suggestion for an exposed form in views ? The scenario is as follows: the user types two letters, the suggestions appear, when he clicks on a ...
0
votes
1answer
57 views

Is there a way to change how a form button looks?

I know how to add a class to a form element and how to add a form submission button, but there are classes that are automatically added to these buttons in my Drupal 8 install. The form I am editing ...
0
votes
1answer
31 views

How do I get the term name in a custom submit handler?

In Drupal 8/9, when you create a new term, the default status message is: Created new term %term. %term contains the term name, which is linked to the term page. I want to override this and remove ...
1
vote
1answer
54 views

Custom form calls different form in modal, submit/ajax callback of second form not called

I created 2 forms: dms_gift_voucher/src/Form/GiftVoucherForm.php ... /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { .... $...
0
votes
0answers
30 views

User own account, cancel account button not showing on edit form

I'm using Drupal 8, on my website I have 2 users roles, both can delete their own data, on role 1 cancel account button show on the edit form in both languages, Portuguese and English(default), but on ...
1
vote
1answer
26 views

How to use Vertical Tabs on ConfigEntity Form

how are you? I've created a ConfigEntity and there a Configuration Form with Fieldsets and Fields. Example: But now I want to change this form to Vertical Tabs, like that: Do you know how can I do ...
-1
votes
1answer
35 views

Alter Submit button of specific form [closed]

I am new to Drupal and want to alter a submit button of a node-edit form. So I wrote a basic module to do so. And it also alters the form button of my form with the id=node_hotel_edit_form. But also ...
2
votes
2answers
96 views

Why can't I see <div> tags added to $form in hook_form_FORM_ID_alter?

I want to modify the $form variable in an implementation of hook_form_FORM_ID_alter but can't seem to be able to set the #prefix and #suffix variables on field widget. /** * @file * Implementations ...
1
vote
1answer
22 views

Sending form to mail from custom module fails without error

I've created a module with a form and a block. When I push the subscribe button, the submitForm function is executed. The successmessage is shown, but no e-mail is send ... There are no errors ...
0
votes
1answer
34 views

How do I send a command after submitting a form?

I need to do something when the user submits a form so that it sends a command to the server, : if($_GET["cmd"]=="save") Got to do something with the thing above, I thought of ...
2
votes
2answers
61 views

Changing 2 Elements on Ajax Callback

I have an element $form['elements']['manufacturer']. On change, I want to change $form['elements']['form_factor'] and $form['elements']['model']. Currently I have: $form['elements']['manufacturer']['#...
0
votes
0answers
33 views

Checkbox Form Element: Displaying checkboxes value based on on/off

I have a checkbox form element that uses taxonomy terms via variable_get as #default_value; storing the result. I don't want to overwrite value, I just want the form to render/display checked ...
0
votes
1answer
32 views

How can I understand when hook_form_alter() is called?

In Drupal 8, hook_form_alter() is invoked multiple times: at page load, submission, after executing custom submission handlers, and back to form action. How can I see at which stage hook_form_alter() ...
0
votes
1answer
27 views

Ajax callback on Views exposed form filter

I'm trying to add an #ajax callback method to my views exposed form filter select box. But it seems the form have some issues with the callback. My code is pretty simple /** * Implements ...
0
votes
0answers
55 views

How can I render a form via javascript without outputting the entire page markup [duplicate]

I'm trying to load a custom form into a div, but when I do, the entire page markup (menu, header, footer, etc) is being output in the div. Is there a way I can only output the form? This is my ...
0
votes
1answer
53 views

Controller is loading twice after search form is submitted

I created a custom module that I consume an external api. I have also created a custom form (its action points to controller url) which filters the data. However, when I press the search button and ...
0
votes
0answers
64 views

Same form displayed twice on same page

I have the same form displayed twice on the same page. It's the comment form . I put it twice on the same page . when I fill the inputs in the second one and I click on submit . I notice that the ...
3
votes
2answers
122 views

Redirect to webform from controller and back to custom form

I have a use case where I'm creating a custom form, but for business reasons, I need to obtain customer information in a separate webform prior to granting access to my custom form. So my workflow ...
0
votes
0answers
30 views

Trigger login / send login credentials from different subdomain

I have my Drupal 9 living on a subdomain like e. g. drupal.xyz.com. Then I have some marketing-related landingpage stuff at subdomain.xyz.com, which is not Drupal, but another system. Now I would like ...
4
votes
1answer
135 views

How do I render a form in a div through a javascript call

I'm trying to load a form into a div using a javascript call. I can get the form in the div, but nothing works (autocomplete fields, wysiwyg fields, custom submit handler). I know I must be missing ...
1
vote
3answers
61 views

Missing form state values after adding submit function

I added a submit function in the form_alter hook when inserting a node: $form['actions']['save_as_draft'] = [ '#type' => 'submit', '#value' => t('Save as Draft'), '#submit' => ['...

1
2 3 4 5
131