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
50 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
1answer
116 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
383 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
50 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
39 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
122 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['...
3
votes
3answers
472 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
34 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
58 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
160 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
136 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
422 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
33 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
80 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
17 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 ...
0
votes
0answers
17 views

Should I use a 'URL', 'Path', or other form field type when the field is used to define the location that a file should be saved

I have an administrative form that allows a user to set the save location of a file. I'd imagine that valid locations would be public://foo, private://foo, and /foo/bar/foo. What is the proper form ...
0
votes
1answer
79 views

How do you add validation (constraints?) on a paragraph? Compare two fields

How does one go about adding validation (contraints?) on a paragraph? I need to compare two entity reference fields on submission. If one field has a certain entity referenced, the other cannot have ...
-1
votes
1answer
40 views

Custom form set custom template [closed]

I have created a custom module for custom form, form is created successfully. But when I open this form then it's open under MYTHEME/template/layout/page.html.twig I just need to open this form in ...
1
vote
1answer
107 views

How alter submit user_pass_reset?

I can alter every form submit in Drupal with this hook: hook_form_alter On the user_pass_reset form there is a button for auto-login from a link. I need to add some custom logic just after the ...
0
votes
1answer
116 views

How do I alter a form using an AJAX callback?

I have this callback function triggered by an onChange() event in another select box. This code, however, doesn't make the field enabled public static function changeForm(array &$form, ...
1
vote
1answer
240 views

Ajax Form on load Event

Is it possible for a Drupal Ajax form to automatically fire a callback when a page is loaded? I know this is possible using an external JS file and doing it through Drupal behaviors, however I would ...
0
votes
1answer
21 views

Adding contacter's email to reply field in contact form email

In Drupal 7, when someone used our contact form, we would receive an email and could click "reply" in the email we received and have their email be in the "to" field. Since upgrading to Drupal 8, our ...
0
votes
2answers
112 views

remove “last saved” and “author” fields in from

How to remove "last saved" and "author" fields in from in Drupal 8? answer over here did not help How do I remove the authoring information? i have tried to hide it via form_alter but no luck... ...
0
votes
0answers
17 views

Custom menu item doesn't show up in admin menu bar for role

I have a D7 site using Admin Menu, and I have a URL defined in a custom menu that I want to display in the Admin Menu bar at the top of the page for two roles - Content Editor and Administrator. I ...
0
votes
2answers
36 views

Unable to fetch admin config form submitted values

I created a admin config form in drupal 8 . I am not able to fetch the saved values using this code. namespace Drupal\courier_quote\Form; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\...
0
votes
3answers
153 views

How to change the title and add a placeholder to password and confirm password field through hook_form_alter?

How can i remove the label of the password and the confirm password field through hook_form_alter functionality ? Tried the below: $form['pass']['#title']= t(''); $form['pass']['#description']= ...
0
votes
0answers
9 views

Render form, hide alle form fields and then show some of them

I'm trying to render the user profile form in a block since i want users to be able to quickly edit certain fields of their user profile. Rather than manually hiding all the fields that they should ...
0
votes
0answers
50 views

Custom handler executes the submission function on pressing “Next” button

I have a custom webform handler built using the instructions on Add a custom submission handler to a form. It works, but the code in submitForm() is executed every time the Next button is pressed on ...
0
votes
1answer
59 views

How to pass values to content creation page to set default values in form elements?

Introduction (not necessarily needed to be able to answer the question) I use Domain Access module to be able to manage different sites from one Drupal installation and a single shared database. I ...
0
votes
1answer
35 views

how to reorganize with twig a form builded in a custom module and keep working ajax callback?

I've a form created programatically with a few fieldset and some inputs in these use ajax callback. The structure is like this : $form['global']['controls'] = [ '#type' => 'fieldset' ]; $form['...
2
votes
1answer
275 views

Is there a way to provide theme name suggestion for form elements?

I'm trying to look for a way to modify the markup for a form element without touching the default theme/template. Upon checking the source code, Drupal does not seem to recommend any theme suggestions ...
0
votes
1answer
129 views

Adding a delete button to node edit form

I need to add a delete button to a node edit form, so in case I open a edit form of the node I want to have a possibility to delete it as well. This edit node form is genereted from a view using Link ...
0
votes
2answers
25 views

Unable to remove label field from the registration form

I am unable to remove the label from a form element of the registration form. I have: Enabled the kint module for debugging Implemented hook_form_alter() and tried to change the form variables ...
0
votes
1answer
42 views

How to use hook_form_alter in the .theme file to alter the form fields?

I need to know how to use hook_form_alter in .theme file as i have to alter the form fields related to user_register_form. I tried putting the below code in the .theme file but it does not even reach ...
0
votes
1answer
52 views

form submitted value as token

I have created a form by extending FormBase class. In form, I'm having a field called "name" where user can input his name. While submitting form, I want that submitted name convert into token so that ...
-1
votes
1answer
50 views

Different registration form per role [closed]

I'm new to Drupal 8 and not sure how I should make this work. I have two users: User 1 is created by admin. User 2 is created by User 1 with predefined role. I want to have different registration ...
0
votes
1answer
286 views

How reset $form_state on ajax call for get real value in submit?

I have see some post about that,but i still have no real answer. In my form, user can select a register address in a select field. When he select an address, the ajax set value on some other fields : ...
0
votes
1answer
38 views

Create URL and redirect?

function news_article_node_submit($node, $form, &$form_state) { // Make a URI link from title of pdf being uploaded if (isset($form_state['values']['field_upload_import_pdf'])) { $file = ...
1
vote
1answer
34 views

How to save file with custom form?

I try to use that script in my Drupal site https://tutorialzine.com/2013/05/mini-ajax-file-upload-form I did not use drupal form api. I used my html same with that script. I created 2 pages with ...
0
votes
0answers
27 views

Nested AjaxAddMore using Drupal FAPI

Using examples module as a reference guide, I'm able to implement the AjaxAddMore functionality into one of my configuration forms, but somehow when I'm trying to achieve the same logic by further ...
1
vote
1answer
321 views

Reset a form element value through AjaxResponse

I have an AjaxCallback which returns AjaxResponse(). I need to change some form element properties like (disabled to true, remove some css class etc which works). But I'm unable to reset the ...
1
vote
1answer
48 views

Use an Address Field with 3 lines for the street

I'm working on an Entity where I created a field containing Address informations (like country, city and street). The default Address Type in Drupal 8 supports only 2 lines for the street information....
0
votes
1answer
28 views

Change field requirements on validation?

I am new to Drupal so forgive my newb question. I am trying to remove the required true from a form field if a user clicks on a certain button so i tried to do it via form validaiton: $form['#...
1
vote
1answer
142 views

Form element replaced via Ajax callback doesn't seem to be submitting or the values are not appearing in buildForm

I'm having a form with a select list and a textbox. On-change of select list will trigger an ajax callback. The callback function will replace the default value of textbox with an updated value. But ...
0
votes
0answers
25 views

WYSIWYG editor not showing result of custom form backend

I've created a module. In this module, I've created a custom form with some parameters. In theses parameters, I have this field : $form[self::DESCRIPTION_PAGE] = array( self::TYPE => '...
0
votes
0answers
75 views

Check if a Paragraph field is disabled/ enabled in form validate

I'm trying to validate a form consisting of Paragraph fields. Some of the fields are disabled. I want to setErrorByName() of those fields which are not disabled and empty. Anyway we can check the ...
0
votes
0answers
45 views

How to redirect to a route on form submission? [duplicate]

I am trying to call a route on form submission using ConfirmFormInterface API . My Submit handler is as follow public function submitForm(array &$form, FormStateInterface $form_state) { $...
0
votes
1answer
193 views

Disable /Enable a multivalued paragraph field on Ajax calls

I have 2 fields in a form. One select list and another entity reference field referring to a Paragraph type (multivalued). The on-change event should trigger an ajax callback which will disable some ...
0
votes
1answer
57 views

Image File field not getting updated

Form function: $form['upload_photo'] = array( '#type' => 'file', '#title' => t('Upload Your Photo'), '#title_display' => 'before', '#states' => array( ...