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
3answers
363 views

TableSelect with drag-and-drop weight

I have a tableselect and I have been looking all over the internet for a tutorial on how to make a tableselect have sorting/drag-and-drop functionality. I have found tutorials for making normal lists ...
0
votes
1answer
406 views

Add Checkboxes to a views listing of titles

I am looking to pull in a views listing of events by title into a entity form. I need help figuring out how to add checkboxes to the views listing of title. This way if someone checks the box when ...
0
votes
1answer
43 views

Adding Constraint to Paragraph field

I have a Content Type with a field that references 6 different paragraph types. The field is set up to accept unlimited values. For one of the types I would like to have exactly four values added. ...
0
votes
1answer
370 views

Get Checkbox Value From Another Form

How do i get the value of a checkbox from another form/page and how do i make it so if the checkbox is enabled, it'll allow a button to be visible? checkbox in SettingsForm.php: $form['#tree'] = ...
0
votes
0answers
19 views

Quantity field and Custom text field is not displaying in add to cart form

My aim is to display two fields in Product page (Custom text and Quantity field). I have created a new custom text field. Finally, I have moved these two fields from hidden to visible mode in Add to ...
1
vote
1answer
29 views

Increase label max length

The default max length for all labels of all field types is 128. The DB can handle 255. So no schema change. How can I change the default max length to 250? I've seen this module https://www.drupal....
1
vote
1answer
1k views

Attach library to custom form

I'm building a custom module (say 'mycalc') with a custom block with a custom form inside. Now I want to attach a library to the form and add some styling and live manipulation. I created the mycalc....
2
votes
1answer
1k views

How to set a validation error via ajax?

I am using the formapi to create a form. On one of my fields I have an #ajax call. When the field is changed I call the function. I recreate the form and then replace the whole form on the page. This ...
0
votes
1answer
63 views

Unlimited Custom Form Fields - Without Ajax

I have a simple form where users can set the number of fields they need. Users may need 100+ fields so I am not using ajax "add more" options. With the below code, everything works (Even though you ...
0
votes
1answer
41 views

Get an Un-submitted/Active Form Field Value in $form_state?

I am unsure how to get unsubmitted/active form field values from a number/textfield into $form_state. field_count could be saved as 4, then is changed to 115, how do I pass that change to $form_state ...
-1
votes
0answers
35 views

How to ungroup address form elements

We're using the Address module to provide address functionality. But its widget is in a container ( details form element) But what we need instead that is to divide the elements, something like in ...
5
votes
2answers
5k views

How to alter a form element's properties before rendering?

Here's a simple task. For accessibility reasons, from a custom module I need to perform alterations on textfield based form elements (such as email, textfield, etc ...) on custom forms displayed to ...
1
vote
1answer
373 views

Captcha on the user_login_form and user_pass form?

just checked on my site and it seems that certain login forms do not have captcha. specifically the form named: user-login-form user-pass I put in user_login_form in the captcha page to make it show ...
0
votes
1answer
89 views
+50

Redirect to a form with an array of Terms as a parameter of buildForm

Here is my use case: 1-I select few nodes from a view with VBO 2-I run a custom action on those nodes 3-As a result, this action create an array of Terms ($resultedTerms) My goal, after that, is ...
0
votes
0answers
17 views

$form_state values are empty after ajax $form modification

Im doing a module to generate form validation on field length, first i display a select of availble content types. When the target content type is selected an ajax request display the end of the form ...
0
votes
0answers
14 views

How to programmatically add fields to a node through a module

I've followed a tutorial here about adding a field to every taxonomy and node and I'm getting an error on installing it. I can get the field, widget and formatter to work, just can't get it to install....
0
votes
0answers
27 views

How to validated form with Ajax fields

I have a drupal custom form with two ajax dependent dropdown fields and five normal text fields. on form submit, all things are working fine except validation of form fields. when I put validations on ...
0
votes
1answer
367 views

Prevent redirect after submitting the form

In Drupal 7 profile2 module, want to make profile2 edit form to stay on the form itself after clicking SAVE button. With the following code, it stays on the form itself and displays the values ...
0
votes
2answers
385 views

How do I alter a field content before saving the form?

I have two fields, Transaction type and Amount. I would like to change the value saved by Amount depending on Transaction type. e.g. Transaction type == deposit , amount is a positive value. ...
0
votes
1answer
386 views

How to store Ajax Return value into variable after clicking the Submit button

I have created form with fields of State and City. After selecting the state appropriate city records will be loaded into city field till now working fine but after clicking the submit button I am not ...
-1
votes
2answers
42 views

messenger()->addMessage not working after a $form_state->setResponse

In the submitForm of a custom form, I have this: switch ($form_state->getValue('suscribe')) { case 0: $iStatus = 1; break; case 1: $iStatus = 3; $sFileName = 'sites/default/...
1
vote
1answer
393 views

Can we call submit handler of one form into another form?

Can we call submit handler of one form into another form? I have two forms say user profile form and choose membership plan I want to unset submit function of choose membership plan and want to show ...
0
votes
1answer
374 views

How to put select option value into particular category in webform module?

I am using webform module and added a select field. My option values are One|Sample 1 Two|Sample 2 Three|Sample 3 Four|Sample 4 Five|Sample 5 Six|Sample 6 But I want these three fields ...
3
votes
2answers
786 views

What is the twig template name for a node edit form?

In Drupal 8, what is the twig template name for a node edit form for a custom content type called for example "device". For a default node we use node-edit-form.html.twig So what is the edit ...
-1
votes
0answers
7 views

How do I integrate the recaptcha module in a contact form with ajax?

I have a contact form on the front page of my site, this form makes the sending of data with ajax, I incorporated the recaptcha but it does not work, any idea.
0
votes
1answer
372 views

Collapsed and collapsible Field Sets in Admin

I have created a fieldset (which groups a field collection). Because it has a few nested levels and many fields, I want it to be shown collapsed. I am trying this code but it does not work. The id is ...
0
votes
1answer
24 views

File upload through form type file

My Drupal version is 8.6.10 I am trying to upload a file through the file_save_upload function and the function is looking for the file in Symfony\Component\HttpFoundation\FileBag Object $...
1
vote
1answer
393 views

How to clear form element values after validation error

I have a rather complex form validation depending on multiple fields. If validation fails, I would like to set the form values (of all or some explicit fields) to an empty value. This is what I tried, ...
-2
votes
0answers
25 views

My site got hangup [closed]

I have a query on a website that usually has heavy traffic. Problem: Site got hangup two times with different errors. 2019-03-08T16:16:27.401498Z 0 [Warning] InnoDB: Table mysql/innodb_table_stats ...
3
votes
3answers
1k views

How to build multivalue form elements using Form API

With the 'field collections' module at the form level, you can create a fieldset (or 'field group') that will accept multiple sets of values. Is there a way to do this with the Form API directly (or ...
19
votes
3answers
13k views

Add classes to form select option item

How can I add classes to a form option tag without JS? At the moment in Form API I can pass a keyed array like this array( '0' => 'option 0', '1' => 'option 1', ) and I'll get html like ...
1
vote
1answer
19 views

Create config object with array containing key-value pairs

We have a custom module, mymodule, that we want to use to create a config object for so that it can contain an array of key-value pairs. We need to be able to click button Add More on the form that ...
0
votes
2answers
379 views

Submit form load results instead of messages

I am testing out the new Drupal 8 custom modules and currently stuck with the submit form handler to load form submitted results in the same page and my current functions of last submit is this (...
1
vote
4answers
297 views

How to to redirect a form to a certain node for anonymous users?

In a custom module, I have a form that is triggered by an option in a menu. I'd want this form to be redirected automatically (without action of the user) to a certain node (/node/2) when the user is ...
0
votes
2answers
45 views

$form_state->setRedirect not working after a $form_state->setResponse

In the submitForm of a custom form, I have this: $sFileName = 'sites/default/files/_private/bulletins/' . $form_state->getValue('adherent')[1] . ".pdf"; $response = new BinaryFileResponse($...
2
votes
1answer
375 views

Custom template for each profile2 profile type edit form

I am working on a Drupal 7 site and for a few days now, I've been struggling with this problem: I am trying to create a custom template for the edit profile form, but there are more profile types. I ...
-2
votes
0answers
18 views

hook_form_FORM_ID_alter() is not working [closed]

hook_form_alter() works fine but hook_form_FORM_ID_alter() doesn't. I created a hook to alter the action after the submission of a form. The hook gets called when hook_form_alter() is implemented, ...
2
votes
2answers
1k views

how to make a form field be required with hook form alter

I want to alter a form to make the revision log be required. with drupal 8, I am adding this in a module $form['revision_information']['#required'] = TRUE; but the field does not become required. ...
1
vote
1answer
376 views

Add taxonomy term in popup

I have a select list with some options. But now I also want an option Other. And when you select the Other option there has to open a pop-up screen with the add term to vocabulary form in it. The term ...
1
vote
2answers
388 views

Hide the title of a form element?

I'd like to use placeholders instead of labels for a form built with the form API. I can get placeholders working well with the Elements module, but now I want to hide the labels. If I just set ['#...
0
votes
0answers
15 views

How do I add a CAPTCHA inside a pop-up contact form?

Inside a pop-up form, I want add Recaptcha, I install Recaptcha module Drupal 8, $form['captcha'] = ['#type' => 'captcha', '#captcha_type' => 'recaptcha/reCAPTCHA',]; and in my twig ==> {{ ...
0
votes
1answer
32 views

Why isn't this Config API Code saving options?

I can see the form, using the Config API, and submit it. However, it doesn't save the changes. Here is my code: <?php namespace Drupal\my_config\Form; use Drupal\Core\Form\ConfigFormBase;...
14
votes
3answers
27k views

Add a custom submission handler to a form

How can I add a custom form submission handler? I tried adding $form['#submit'][] = 'mymodule_form_submit'; or $form['actions']['submit']['#submit'][] = 'mymodule_form_submit'; to hook_form_alter(). ...
0
votes
1answer
382 views

Drupal forms, how to output content of a date (array)

I have a form made with the Drupal Form API, there is a date field which result I want to output to the user in an email. I'm only getting array as output, so how do I access the keys and values? ...
2
votes
1answer
395 views

ajax form, send data from js modal to form

I have the following form: When I click the "Add Filter" button, I need to open a modal with a select input element. Then I need to send the user's choice back to the Drupal Form instance and extend ...
0
votes
1answer
384 views

How to use form_set_error if no form field is involved in the error?

In a form_validate hook, I have some custom validation and I'm using form_set_error('field_foo', "error_message"); to show validation errors. If the validation returns an error that is not linked to ...
0
votes
1answer
383 views

drupal 7 form is not submitted with arg() in url

I have a list of items. By clicking on an item I open a form at /items_form/123 where 123 is the itemid. When filling the form I use the arg() function to get the 123 and read some data from the ...
0
votes
1answer
25 views

Drupal 7 chosen module use ajax to fill the select

I have two select elements and depending on what I select in the first select element second should fill from ajax call. First one is the simple select second one use chosen. The problem is if I fill ....
0
votes
0answers
11 views

tableselect default checked specific values

foreach ($courses as $user) { $options[$user['uid']] = array( 'coursecode' => $user['coursecode'], 'coursename' => $user['coursename'], ...
2
votes
1answer
481 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....