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
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
53 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
36 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
73 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
79 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
181 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
20 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
80 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
16 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
32 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
100 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
46 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
56 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
33 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
156 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
105 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
33 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
39 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
45 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
200 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
32 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
23 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
197 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
36 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
27 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
76 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
19 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
67 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
23 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
129 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
0answers
27 views

Custom Form Multiple Image Upload - remove “Remove Selected” with checkbox

In a Drupal 8 Custom Form, I have a field of type managed_file with multiple set to TRUE. When the form is rendered and more than one picture is added, each picture has a checkbox and at the end, ...
0
votes
1answer
53 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( ...
0
votes
1answer
42 views

Why can't I change textfield #default_value based on checkboxes' values after an AJAX response?

I have been trying to learn Drupal forms with AJAX recently and from my current understanding of it I thought I should be able to do something like presented below (I wanted to store all selected ...
0
votes
1answer
22 views

Embed unique custom form in all rows of a view

I want to create a custom form that will be embedded on each row for visitor to submit an email for that specific row. I suppose I have to create a custom form (which I have done before) but how do ...
1
vote
0answers
45 views

How do I set a url query parameter node/{node}/edit for a specific content type?

I'm trying to add a taxonomy term from the node in question as a url parameter, but am struggling to figure out how to do it without just going through the site and modifying all of the links that ...
0
votes
2answers
88 views

Show taxonomy term for administrators only in node creation form

I have a content type Topic. The topic has the taxonomy terms -health -fitness and -news. I only want certain roles like administrators to be able to see and use the taxonomy term - news when creating ...
1
vote
0answers
14 views

Rendered entity display mode has gone [duplicate]

I'm trying to create a paragraph with an entity reference field, that renderes a contact form. My problem is that I'm not able to choose the Rendered Entity display mode, for my field. As you can ...
0
votes
1answer
34 views

How to get form values in URL as keys of an array

I have a custom form with min and max price value: $form['price']['min'] = [ '#type' => 'hidden', '#default_value' => isset($_GET['price']['min']) ? $_GET['price']['min'...
0
votes
0answers
22 views

Howto check if a form contains custom type field in hook_webform_submission_form_alter?

How to check if my custom element is added to form in hook_webform_submission_form_alter. Below is the screenshot what i am getting in form array. Custom composite element can be nested under 3 or 4 ...
0
votes
0answers
17 views

Getting problem in drupal form validation having ajax fields and other fields

In Drupal 8.5.6, I have a form with one ajax dependent dropdown field and two more other normal text fields. But when i give validation to form, when text field validation fails ajax fields gets reset....
1
vote
1answer
42 views

Why does the same form/field appear diffently depending on the browser?

I have a custom content entity created with Drupal Console and the corresponding CRUD forms. In this entity there is a field defined this way: $fields['startdate'] = BaseFieldDefinition::create('...
2
votes
2answers
159 views

How to change the value of the publishing status checkbox to false by default?

I want that checkbox to be unchecked by default, because currently it's always checked. And I want this result: The structure of my content is as follows:
0
votes
0answers
51 views

How to make default user registration form to multi step?

I want the multi-step sign-up form for my drupal7 website. So I have 2 approaches are here. https://www.drupal.org/forum/support/module-development-and-code-questions/2010-12-15/altering-user-...
1
vote
1answer
186 views

How do I add reCaptcha to a form programmatically? [closed]

I have a custom form on my site, and I want to attach a reCaptcha to it. I wasn't successful using the Drupal 7 code for this. Suggestions? This is the Drupal 7 code I'm using: $form['recaptcha'] = ...
0
votes
3answers
53 views

Is the current form an entityform form?

I am using entityform module on subscribing certain organic groups forms. I only need to add some custom submit logic when unsubscribing the form if the subscribe form was created with entityform. ...
0
votes
0answers
55 views

Passing field values to hook_mail_alter()

I'm new to Drupal so I'm sure this is a simple question for some. I looked around but I keep finding either D6 or D7 solutions. Nothing on 8. This is what I have in my form alter. if ($form_id == '...
0
votes
0answers
29 views

Textfield is not made visible when the radio form element is checked

In my form I have the following: $form['text_2'] = [ '#type' => 'textfield', '#title' => $this->t('Text'), '#default_value' => isset($config['text_2']) ? $config['text_2'] : ''...