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

Don't use it for entity or entity field forms.

0
votes
0answers
6 views

How would one iterate over dynamically added form elements in Drupal 8?

I got AJAX working with the AppendCommand, so that everytime the Add button is clicked, a new "section" is added to the form. My problem is, how do I iterate over all these elements in validateForm ...
0
votes
1answer
9 views

Missing argument 1 for hook_menu()

I'm getting this error in my custom module. [warning] Missing argument 1 for signin_menu(), called in /public_html/includes/menu.inc on line 2813 and defined signin.module:2 here is my code to ...
0
votes
1answer
19 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
13 views

how to create content types dynamically in Drupal 8.5? [duplicate]

I am using Drupal 8.5. I want to create custom content type dynamically through custom form. Like content type name and fields are given in form according to which content type will be created after ...
0
votes
0answers
12 views

How to make the placeholder appear in Formatted text field appear?

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 ...
0
votes
1answer
25 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 ...
1
vote
1answer
22 views

Use $form['attributes']['class'] in a hook_form_alter without overriding the original module

I am trying to create a custom module that adds a CSS class. I am trying alter an existing module using hook_form_alter To be precise, my original module has the following code $form['attributes']['...
0
votes
1answer
18 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
12 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
28 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
14 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
23 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
133 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
35 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
16 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
26 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
18 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
31 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
31 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
18 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
10 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
21 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
11 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
30 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? ...
0
votes
0answers
10 views

How to set an open/closed date in EntityForms?

Is there any way in which I can set a specific open/closed date for an entityform on Drupal? I know in the Registration module you can do that, but I haven't found a way to do that in the EntityForm ...
1
vote
1answer
25 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
29 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. $...
0
votes
1answer
23 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
134 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
22 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
15 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
20 views

Attaching JS in form works, CSS not

I am trying to insert a piece of JS and CSS conditionally in a module to customize a view's exposed block. function xxx_form_views_exposed_form_alter(&$form, &$form_state, $form_id) { ...
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
52 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
20 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
13 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
38 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
19 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
26 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
32 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
22 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
36 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 ...
0
votes
0answers
30 views

How can I save DOM element changes from jquery, to the database on form submission

I've done this at least once before, but I can't find where I did it. I have a CiviCRM form which I am running calculations on and editing the DOM with the new values. The problem is that the DOM ...
2
votes
2answers
43 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
69 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
15 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
26 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
21 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
32 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.