Questions tagged [forms]

Use it for questions about the Form API. Don't use it for entity or entity field forms.

Filter by
Sorted by
Tagged with
0 votes
1 answer
964 views

Custom Ajax forms with managed_file form element

We have a form with three fields - where depending on the value of the first select field, we will show the other two form elements - one select field (the options depends on the value of the first ...
0 votes
1 answer
401 views

How to hide profile2 field label and captcha label in registration form

I've tried using 2 different functions, where both successfully sets the value to 'invisible' with a dsm($form) check. However, the label is still being displayed. function MYMODULE_form_alter(&$...
0 votes
0 answers
33 views

How to add a reset button to forms that isn’t a #submit type?

How do I add a reset button to a form? I have a form with a CKEditor and other fields, plus hidden fields. How do I reset the form so all fields are empty?
0 votes
2 answers
2k views

Setup custom required field validation for a field in custom form

How can I setup custom required field validation message for a text field in my custom form. I tried below code. But it is not working. It always showing 'Please fill out this field'. $form['...
1 vote
0 answers
994 views

Field Entity Autocomplete filter the published nodes [closed]

I have a custom form with the following autocomplete entity element. $form['my_element'] = array( '#type' => 'entity_autocomplete', '#placeholder'=>'Search', '#target_type' => 'node', ...
1 vote
1 answer
468 views

Prepend drag icon to each form element

I am building a configuration form with a few sortable elements. I know, you can build a table using builtin Drupal draggable functionality (drupal_attach_tabledrag), but it's a bit too complicated ...
0 votes
1 answer
494 views

Profile2 regpath move account email field, into profile2 form and handle submit

I have a profile2 regpath displaying my profile2 form, and the system default account registration form below it. I need to move the account email field up into the container with the profile2 fields. ...
0 votes
2 answers
1k views

How do I implement the login, register and "Forgotten password" forms?

I'm trying to implement the three Drupal 8 user forms : login, register account and forgotten password forms. I'm creating custom pages in my module for each one of them because I want to display ...
4 votes
1 answer
963 views

Prevent dual submit on form submission

I've got a form that submits via AJAX and in the callback I need to rebuild certain parts of the page to reflect the newly submitted data. One of these parts is the form, which I need to clear all ...
0 votes
0 answers
37 views

What's the standard way of passing a return URL to a form?

The scenario is simple. I've constructed a Link object whose URL points to a form. I need a way to pass a URL to that form so that proper redirection can happen after the form is submitted. Passing a ...
0 votes
1 answer
525 views

How to add HTML5 attribute "autocomplete" to form fields?

According to an accessibility test, I have to add the HTML5 attribute "autocomplete" an the proper tags to all form fields on my website where the user fills in his/ her personal data. E.g. "Your E-...
0 votes
1 answer
470 views

Alter Registration Form Text

I am trying to alter the email description text on my user registration page. I have added the following to the bottom of my template.php file but nothing is happening. It seems like the function isn'...
1 vote
1 answer
2k views

How do I set the value of a hidden form element using form_set_value()?

When validating a form, I need to set the value of a hidden form element. I tried using this code, but it didn't work. \Drupal::formBuilder()->setValue($form['maintenance_type'], 'R', $form_state); ...
1 vote
1 answer
788 views

How do I remove webforms from content types?

Currently, our site is built so that anytime a specific type of new content is created, the page automatically includes a form required for the end user. Due to tracking issues we're having with ...
0 votes
1 answer
1k views

Multiple Different AJAX Enabled Forms on the Same Page

I currently have a form that is being loaded by AJAX and is working perfectly. I now need to add a second form (Add Single Stat) to the same page via AJAX as well. The Add Single Stat form is being ...
0 votes
1 answer
2k views

How to display a form in controller method

I have a form defined in mymodule/src/Form/myForm.php namespace Drupal\mymodule\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; class myForm extends FormBase { /** * ...
2 votes
1 answer
519 views

Multipage Registration form, Confirmation Page Security Issues?

I have a multipage registration form working on a site, but the confirmation page is supposed to show some of the information (account name and other data) after the account has been submitted/created....
1 vote
2 answers
950 views

Check if form already failed validation

I added a validation hook to a node creation form. For my project, i need this validation only ONE time: basically i just check if a value already exists in the DB and i notify it to the user. If the ...
2 votes
2 answers
2k views

Form with two submission buttons

I try to create a form with two submit buttons and each button will use a different function: the default submitForm function and a custom submitFormEndSession function. So I have this code: class ...
-1 votes
1 answer
67 views

How can I compare date time values in a content form?

I want to use getString method instead of [0]['value'] how do i do that if possible and is there any other way? -This is the array i am getting when dump their values dump($form_state->getValue(...
0 votes
1 answer
2k views

How can I set value to hidden field (Form Api) and send them with post method?

I’ve created a form with Form Api in a custom module. I send datas with post method to a web service. In buildForm() $form['mode'] = array( '#type' => 'hidden', '#value' => '...
0 votes
2 answers
3k views

How to send email to submitter in a webform?

I have a webform and i want to send by mail this webform to submitter. For the moment, i created an hidden field with token [current-user:mail] and i chose this field in adress. I think it isn't very ...
0 votes
1 answer
435 views

custom module to create multiple forms with pop-ups

I am working on a custom module to create a form. Functionality of the module is as follows: The first form has an url, on clicking the url it should show another form as a pop-up. How can i call ...
0 votes
1 answer
665 views

hook_form_alter #attributes and #disabled

I'm using Drupal 7 and Advanced forum. The users when will create a new topic will be able to select the forum container and forums, but if they select a container, an error will be showed. I want ...
0 votes
1 answer
633 views

Use ajax to save modal / dialog form instead of page reload

I'm looking for a way to save modal & dialog forms through ajax instead of redirecting the user after the form submit. Ajax is quite unknown territory to me. I've found several interesting topics ...
1 vote
1 answer
988 views

Use hook form alter to change input type

I am trying to change the input type on an ubercart checkout form using hook_form_alter. I added an extra field using the uc cart extra fields pane module but there is no option to add e-mail - only ...
2 votes
1 answer
819 views

Submitting a form causes 'secure connection failed' error that persists

I've got a SSL certified server running drupal 7.37. Everything was working fine until I started adding form submission to a module I'm working on. As soon as I submit the form, I get 'Secure ...
-1 votes
0 answers
31 views

How to use the Tableselect element for an order-able list of items?

It's been a minute since I have used tableselect. I want to present a user with a list of sortable options that have checkboxes to indicate they are on or off. See this screenshot: While the table ...
0 votes
2 answers
482 views

Call to undefined function entity_create()

i try to include a node creation form by a field attach form. So i try to load the entity of a custom content type created by the back-office with is called 'friterie'. But when i call the ...
-2 votes
0 answers
53 views

How do i get all the fields just below there respective types when click on their respective checkbox in form?

I have to create a drupal10 custom form -> In this i have created a checkbox with all the content types and when i click on any of the content type the ajax callback occurs which fetch the ...
0 votes
1 answer
1k views

How to set default value for entity reference programmatically in a form?

I have a custom form that I created programmatically. $target_type = 'node'; $selection_handler = 'default'; $selection_settings = ['page']; $data = serialize($selection_settings) . $...
0 votes
4 answers
2k 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']= t(''...
1 vote
2 answers
1k views

Redirect to Different URl on validation errors in form builder

I am using drupal 8 fapi and i have user case as below I have a form on https://example.com/landing-page and I submit the form and there are validation errors .the page should reload as https://...
1 vote
1 answer
471 views

Form is not being rendered in template file

I have tried drupal_render,drupal_get_form etc for rendering the form,but the form is not being rendered. Is there any error in code or else what else should i add to the code so that it works. ...
2 votes
1 answer
2k 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 ...
9 votes
5 answers
18k views

How do I prevent a form from being cached for anonymous users?

I have a form that is pre-populated with information specific to an anonymous user's session information. However, the form appears to get cached for all anonymous users by default. 'Internal Dynamic ...
3 votes
1 answer
514 views

How do you keep the login block on the same page when validation fails?

On pages where the login block exists, I need to stay on that page (and preserve query string arguments) if the validation fails when submitting the form. Does anyone have any idea how this could be ...
0 votes
1 answer
84 views

Make a custom action with form

I am trying to make a custom user action where the selected users will have a node created manually, however I need to create a form to save the data that this node will have, such as: title, start ...
0 votes
1 answer
652 views

Pager not working when $form['table'] is called with AJAX

For a statistics page I let users select the right file in a select list. After that I generate a table with stats. This table also has a pager (that worked without the ajax part). Now I did ...
1 vote
1 answer
47 views

How to create a page with a specific form display?

And how do form displays work? I have a content type (Sketch) with an image. As an authenticated user, I can create a node of that type from /node/add/sketch, but that uses the default form. How do I ...
0 votes
2 answers
763 views

Why can't I modify my comment form using hook_form_alter

I have enabled comments for a custom node type. I am trying to theme that comment form using hook_form_alter(&$form, &$form_state) (For example, I'd like to remove the label of the ...
1 vote
0 answers
36 views

How can I create a custom "Add to cart" form?

I'm developing a basic Commerce shop with Drupal 10. The product type is clothing, which has a single product variation (product_size) and three different product attributes for that variation. The ...
1 vote
1 answer
422 views

Change mark-up with a textfield using Ajax

In a form I have a field where the user have to enter the name, after this I have to update a markup with data from an external DB using the textfield as a parameter, How can I do this or even Is this ...
1 vote
1 answer
515 views

Form submit POST renders page before submit handler is called

I have a search form in the header that is simply adding a search term to the current URL. If you are on example.com/list-page and submit a search, it just sends you to example.com/list-page?search=my-...
1 vote
1 answer
928 views

Set select list option value

I'm trying to set value of select list programmatically with hook form alter I have select list with options: $options = array(125 => 'USA'); and setting value like this $form['...
0 votes
1 answer
582 views

Change theme template for one form

I try to change a the theme template for one form. I do not want to use theme suggestions as I only want to use a different theme in one case, and if I add a suggestion, it is always used. (maybe I'm ...
1 vote
1 answer
1k views

How to create an Enquiry form with ability to submit a collection of enquiries

I am building a new site which has a large selection of different products/services on offer, the information for each is shown in it's own node. If the user has interest in a number of these ...
0 votes
1 answer
398 views

How do I conditionally add a field?

I'm trying to find out any example of adding new conditional field using ajax in Drupal 8 form API, but I can't find it. This is my code. $form['name'] = array( '#type' => 'textfield', '#...
0 votes
1 answer
402 views

Can I add elements to a field widget with AJAX?

I want to add fields depending on the first option selected. I also made a form with a similar behaviour but it wasn't a field widget. I used this module as an example to make the form I'm not sure if ...
0 votes
3 answers
968 views

How to set widget for a field on a custom form?

How do I set the widget to be used for a field on a custom form? I am surprised I haven't been able to find something covering this. Sort of expected it to be something like: $form['interest'] = [ '#...

1
2 3 4 5
137