Stack Exchange Network

Stack Exchange network consists of 174 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.

0
votes
1answer
18 views

How to render a variable which is having a wysiwyg type format?

I am creating a variable in admin section that is of form type #type = text_format to get wysiwyg kind of editor. But having difficulty while displaying the field value in template file. I am trying ...
0
votes
0answers
25 views

How can I iterate over dynamically added form elements?

I got AJAX working with the AppendCommand, so that every time the Add button is clicked, a new "section" is added to the form. How do I iterate over all these elements in the validation and ...
0
votes
1answer
46 views

How to properly alter a field description in hook form alter

I am altering a field description (help text) based on certain conditions. However, sometimes the description element to alter is set at $element['value']['#description'] = $new_description; And other ...
0
votes
0answers
30 views

How to make placeholders appear in formatted text fields

In the Manage form display section of a content type, I configured placeholders for all text fields. The placeholders appear for all fields configured as plain text fields. However, they do not appear ...
0
votes
1answer
37 views

Alter The User Login Form Into Multi Steps

I want to alter my default user login form into multi step. therefore I have wrote a code which I'm pasting below. but this code is not working, whenever I click on "Next" button it will return on the ...
0
votes
2answers
32 views

Form #states visible for numeric values

The form has two radio buttons like follows.The "design" radio field should be visible only when user selects 'Ten' or 'hundred' from the "price" field. If user choose 'other' it should not be ...
1
vote
0answers
17 views

Combining entity forms on one page breaks file upload

In Drupal 8 I have combined a number of custom entity forms on one page using this example. Everything works perfectly except for file uploads which do not load. In the console it returns : XHR ...
0
votes
1answer
31 views

How to add two extra buttons in a form to do extra actions with form data

I have a simple custom form with 3 submit buttons - one that calls the default hook_form_submit and generates a table. The submit as the rebuild as TRUE: $form_state['rebuild'] = TRUE; that shows ...
0
votes
0answers
28 views

How to Regenerate CSRF token on Ajax callback handler

For some reasons, I don't want to rebuild the whole form on Ajax, but I want to regenerate CSRF token on ajax callback handler, Is there any way to regenerate form CSRF token on ajax callback handler?...
0
votes
1answer
31 views

Alter existing form and add element with an ajax “add more” button

I am altering the field settigns form, in order to add custom settings. I used the example module as a guide and added my code in the following manner: /** * Implements hook_form_FORM_ID_alter() for ...
5
votes
1answer
204 views

How to remove unwanted form state values before validation

What is the good way of validating a form in Drupal 8 ? I have a bunch of fields which are supposed to be filled by a positive numeric value (and that's all, no other input types, just positive int). ...
1
vote
1answer
48 views

How to programmatically populate a country field

We are using the Countries module to provide country fields where editors can choose a country and it gets displayed in the frontend. Which works absolutely fine. But we want to fill that field ...
0
votes
0answers
38 views

Disable Bootstrap Tooltips for Individual Form

Is it possible to disable bootstrap tooltips for an individual form (all the components in the form)? I know I can do it in the Bootstrap settings, which will turn off tooltips for all forms, but I ...
0
votes
2answers
28 views

Custom save message for site information form

Folks, I need to alter the site information form. I used api_form_system_site_information_settings_alter hook to do so. After submitting I need to print a custom message. I used one submission handler,...
0
votes
1answer
21 views

hook_form_form_id_alter doesn't save data by default

I use hook_form_form_id_alter() to edit the user_form. I'm creating some checkboxes and textfields. Thats working fine. I also can output the values, when clicking the submit button. But it doesn't ...
0
votes
2answers
69 views

Validation with hook_form_alter()

In Drupal 8, for the Comment entity, I want to validate an integer field (stored as field_nieuwe_waarde_value). In each comment posted for a node, it needs to be greater than the value for the ...
0
votes
3answers
41 views

Modify a custom block field value with hook_form_alter and validate

I'm trying to modify a custom block form with hook_form_alter .In its validate function I have a case where one of the field value needs to be unset. For modifying its value I tried with $form_state-...
0
votes
1answer
42 views

My Ajax call for my submit button does not work?

I am building a form with the form builder but I can't even get my button to use its ajax function to callback. Instead of doing a normal ajax call on the page, it reloads the entire page. What am I ...
0
votes
1answer
17 views

On Imported content I am getting the error Text format field is required

I imported some content to a content type on a csv which imported fine but when I went to edit and same the content I get the error Text format field is required. Is there any known way to fix this? ...
0
votes
1answer
27 views

How can I toggle required field?

Using Drupal 7. I'm trying to toggle required field based on the click of a radio button. I already tried the proposed solution in this post but it did not work. Here is my code: $(context)...
0
votes
0answers
17 views

Setting the default value of the country field in an address with tokens and hooks

I would like to set the default value of the country in the Drupal address field (address module) with a country that I have collected in another process on my site. It would be great if I could "...
0
votes
0answers
37 views

Show specific number of items on paragraph field

I have configured a field like this: When I create a Node, the field shows like this: How can I, programmatically, start this field with two elements and not have to click on the "Add pet" button? ...
1
vote
1answer
64 views

EntityQuery not returning content based on language

I'm trying to get a list of all of a specific content type, but my entityQuery is only returning the original language of the site (English). Here's my code: public function ...
-1
votes
1answer
84 views

How can I return HTML form in BlockBase build function?

I include some form from API. And I want to include it in block, using Drupal\Core\Block\BlockBase. My function return HTML tags, that has tag <form>. But function build() return empty array. $...
1
vote
1answer
43 views

Error 404 when upload image in profile installation

I am installing a custom distribution, I have created a form: my_distribution.install: /** * Implements hook_install_tasks(). */ function my_distribution_install_tasks(&$install_state) { $...
-1
votes
1answer
23 views

Load module config into Javascript from a different module

I have two Drupal modules. One is a shared module that provides a JavaScript library. The second is a module that builds a form which uses that library. Lets call them modlib and modform. They've ...
0
votes
0answers
314 views

Is it possible to have two forms displayed in two tabs but each in its own class?

I have a custom Profile Edit form, and then I want to add a Deactivate Account Form, displayed in a tab "Deactivate Account" in the custom "My Profile" page. How do I render this Deactivate Account ...
0
votes
1answer
31 views

What message is throwing InvalidArgumentException(s) in my contact forms?

When submitting a contact form it redirects to a WSOD and this is logged: Uncaught PHP Exception InvalidArgumentException: "$string ("Message") must be a string." at /Applications/MAMP/htdocs/onb/...
0
votes
0answers
48 views

Inline Entity Form validation for node entity types

For node inline entity form validations the solution suggested in this post "[Inline Entity Form validation]"1 did not work for me. Following is the code I've written, the similar code was working ...
0
votes
0answers
28 views

Using hook_form_alter() to add the “Select a value” option in the select list of a required field where it is not present [duplicate]

For some select fields, the "-Select a value-" option is not present when the field is made required. The first value on the list is presented. This is the case for, for example (and not limited to)...
1
vote
1answer
79 views

Multiple form buttons with AJAX, how to update form state storage data?

I have a form built with the Form API that has multiple button form elements. I don't want any of these to submit the form normally, I want them to utilize #ajax and callbacks to update the display. I ...
0
votes
1answer
42 views

How to add a title text input to an image field node form widget

If you have an image field widget in a Drupal node form you can automatically edit the image alt text in there, but is it also possible to add a title text field? When I install the File Entity ...
0
votes
0answers
16 views

Adding template to a form stops forms submit/validateForm handlers from executing

Ok not entirely sure if this is a bug with Drupals Form API or not, so thought I would ask here before opening an issue. I have built a custom form using Drupals Form API and it all resides within a ...
0
votes
1answer
45 views

Using hook_form_alter() to add the “None” value in the select list of a required field

When a field is required, Drupal removes the default "-None-" value. However, also for a required field, "-None-" is very valuable as it requires the user to make a deliberate selection (put the ...
0
votes
0answers
24 views

Change the HTML inputs in a datetime field

I have a multivalue datetime attribute where the date part is calculated from another field and then incremented based on the time part (e.g., start at the given day, 11pm; if the following time is ...
0
votes
1answer
51 views

How to remove field from form and configuration?

We have a custom module, mymodule that has a form, mymoduleForm with two fields: enabled content types and urls. We no longer need the enabled content types field on the form and want to remove it ...
0
votes
1answer
180 views

How do I add edit/delete buttons to a custom module items list? [closed]

I have a custom form on my development site for visitors to create requests, with 3 fields: name, contact, and request. This is the code in RequestForm.php. public function getFormId() { return '...
0
votes
1answer
31 views

How to make file description field as required?

I would like to set the file description as required. I tried it with this code: function mymodule_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) { if ($form_id ...
0
votes
1answer
37 views

How do I use and administrative form and save a message?

I followed the instructions on Step by step guide to creating an admin form in Drupal 8. I typed in a welcome text into the admin form and saved it, but after saving the form was empty again. I am ...
2
votes
2answers
68 views

Pass Preprocess Values From Custom Module to Custom Form

My use case: I would like to create a unique textfield per region in a custom form. MYMODULE/MYMODULE.module: function MYMODULE_preprocess_region(&$variables) { foreach (array($variables['...
2
votes
3answers
172 views

Hook_form_alter for changing field labels doesn't work of user registration page

Can anyone tell me why this isn't working (in the below code, or other factors preventing the insert by the hook)? I don't get an error message or page, the field labels are simply not overwritten......
0
votes
0answers
24 views

Fulltext Search in Entity Reference Autocomplete Widget

Given: Node type "Article" with fields: title, entity reference field "Related article" to node "Article". The "Related article" field is shown as an "Autocomplete" in the article form. Search API ...
0
votes
1answer
36 views

Adding a view to node edit form

How to attach programmatically a view to the edit node form in Drupal 8? In D7 I could achieve this by using this code /** * Implements of hook_form_alter(). */ function MYMODULE_form_alter(&$...
0
votes
0answers
22 views

Custom fields not visible in Form mode display

The below issue drives me nuts! Through the display form modes, I created a custom display. I added some fields in the display (started with custom fields, but also tried standard fields) None of the ...
1
vote
1answer
73 views

Where can I alter the labels used on the login form? [closed]

This must be configurable somewhere, surely, but I just can't find where. I'm sure I'm doing something silly. Apologies for such a simple question.
0
votes
0answers
95 views

How to add custom AJAX functionality to views form

I need to add a button to an exposed views form that is available for logged-in users. This button should perform some actions via AJAX when clicked. The form has AJAX enabled. I used the following ...
0
votes
2answers
152 views

How to overwrite a file upload so that the filename is always the same?

I am trying to implement a file upload form in which files are saved. I had written the following code <?php /** * @file * Contains \Drupal\avenue_product_import\Form\avenue_product_importForm....
1
vote
1answer
29 views

Two forms on one page break submit

I have two forms on a node page (the comment one + a custom form). Ajax is not enabled for both of them but still, when submitting the custom form form_set_error or durpal_set_message are not ...
2
votes
1answer
54 views

How to check “Show as expanded” by default on the Add menu item page

I need the 'Show as Expanded' checkbox on the Add menu item page to be selected by default. I created a module, 'expand_menu_items', and tried a hook_form_alter function to get the id, apparently it'...
0
votes
0answers
14 views

How alter province (administrative_area) in address field

In my project, I need to alter address field. I want to change type of province (administrative_area) from textfield field to select list with specific options. I tried to do it via hook_form_alter ...