Stack Exchange Network

Stack Exchange network consists of 175 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
72 views

Programmatically render a custom form in a view template while passing view argument to form

I have built a custom form (in its own module using FORM API) and have exposed this form also as a block using Plugin API. I can add this form fine to page and get it to render using Block Layout but ...
0
votes
1answer
112 views

How to display a warning message

I have a form with a required checkbox. If the box is not checked and I confirm my form, I receive a warning with Chrome (see the screenshot). How to display a warning message in drupal ? In my ...
0
votes
0answers
86 views

How to use form input fields nested in tableselect

I'm trying to build a customized, Excel-style bulk edit form for one specific, multi-value field used in multiple nodes. I thought a tableselect form render element would be a good start, but I'm ...
0
votes
1answer
53 views

How do I disable a fieldset?

I read How to unset fieldset in hook_form_alter? to disable fieldsets in an hook_form_alter() implementation, but it didn't work. I tried using the following code, but neither of them worked. // ...
1
vote
1answer
37 views

Custom submission handler doesn't save the node

I have two form submission buttons: the normal one and one added via hook_form_alter. I'm currently using the normal default one as a save button which updates the node content as normal. The second ...
0
votes
1answer
110 views

How to handle Custom Validation in inline entity Form?

I'm using Drupal8's inline entity form and is having issue with writing custom validation. I found few links and wasn't helpful at all. Does anyone know how to handle this?
0
votes
0answers
44 views

How can I translate the “Published” checkbox?

On the node edit form, I would like to translate the Published checkbox in Foo only for a certain content type. Therefore, I implemented hook_form_alter(). I cannot find the label string in any ...
1
vote
1answer
59 views

How to display the path without alias?

With Drupal 8 and Commerce 2.10 I created a php code to display the link of my store. When I go to the link, it displays: https://www.domaine.com/shop/name I want to display without alias: https:/...
0
votes
0answers
39 views

How to insert the store ID in a plugin?

I have a Drupal 8 site with a marketplace (several stores). I want to display in the "review" step of the "Checkout Pane" a checkbox with the sales terms. The terms of sales are accessible for each ...
1
vote
1answer
66 views

With a custom form, how to sanitize user input before query gets to URL?

I followed this tutorial to create a custom Search form that takes users to the main search page with a query in the URL (meaning it uses a get method). This gives me more flexibility than using an ...
0
votes
1answer
44 views

How to set a multi-value image field's default value from author's profile field on a node create form?

On /admin/config/people/accounts/fields page, there is an optional multi-value image field field_proof_images. There is a content type Proof, I reuse the field_proof_images in Proof. Then on /node/...
6
votes
1answer
815 views

How to prevent an Ajax form from submitting

The below code blocks any non-ajax form from submitting. $(this.form) .on('submit', function(event) { if (/* Some condition */) { event.preventDefault(); } }); In Drupal 8, how can ...
0
votes
0answers
32 views

Set Custom “Paragraph Type Icon” For Paragraph Type With Module During Install

Drupal 8.x I have a paragraph that is installed via a custom module, this is done with .yml files in the MYMODULE/config/install/ directory. I would like to have a custom icon added to the "Paragraph ...
0
votes
1answer
34 views

File upload with auto compression

I have written a module with form api which can upload image with dynamic file name. I want to upload that file with auto compression. I cannot understand how will I achieve this. How can I implement ...
1
vote
1answer
54 views

How to compare text input with a user password stored in the database?

I've been trying to compare password values using a custom form. Actually I want to show a relogin form after a particular amount of time. So I have created a custom form with two fields – email and ...
-1
votes
2answers
181 views

How to display a button with “markup”?

I created a custom module and in the code below the button is not rendered, there is only the text : $form = ['#markup' => '<button type="button" class="btn btn-success" disabled="disabled">...
0
votes
1answer
94 views

How to add a time picker in datetime form elements

I have made a module that display a form. One of the form elements is a datetime field. $form['FirstDate'] = array( '#type' => 'datetime', '#title' => t('First date-time'), '#...
0
votes
1answer
33 views

Manage Form Display - not saving configuration

i'm working on a pretty big User/register site. Today i created some more fields. Now i want to order them properly with the "manage form display" settings like i used to but it is not working. ...
0
votes
1answer
30 views

Elements not showing in $form object

I have a webform with some fieldsets. Within each fieldset is a set of input elements that are the same for each fieldset, and each set of elements has the same machine name. One of the elements is a ...
1
vote
0answers
119 views

Entity Form: Override Submit Handler with Custom One

I'm loading a field collection item form inside of a formatter. Below is the function loading the form, which works. However I do not want to call the normal field collection submitForm handler, I ...
0
votes
1answer
78 views

Off canvas dialog using a button

I am trying to adapt the relatively new off canvas dialog introduced in Drupal 8.5. It is suggested to use it with the Drupal Form-API and a link element like this: $form['off_canvas'] = [ '#title'...
0
votes
1answer
48 views

How to iterate over AJAX-added form elements

In this snippet, located under src/Form/DocumentCreationForm.php, I create an AJAX callback that adds more section elements to the form when the add section button is clicked. Now I'm trying to read ...
0
votes
1answer
48 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
1answer
107 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
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
33 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
23 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
33 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
35 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
58 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
358 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
60 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
75 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
30 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
28 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
166 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
59 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
64 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
33 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
40 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
116 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
128 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
44 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
40 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/...
1
vote
1answer
204 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
84 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
17 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 ...