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
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 ...
1
vote
1answer
21 views

Prevent clubbing of server side error messages on top

I have inline form errors module enabled on my drupal 8 site. The server-side errors that appear on form submission are appearing as clubbed together like below: How to change this error language and ...
0
votes
2answers
129 views

Custom Entity: define a view in entity reference field

I defined a custom entity and for a entity reference field I want to set the view reference widget and a view/ display to be used instead of an autocomplete. I tried many different settings - nothing ...
-3
votes
0answers
18 views

How to show/hide div based on the radio button selection in form alter

I have a content type, having a field with radio buttons. Radio button describes a list of the interest. Field Name: field_interest Field Type: Select List (checkbox-radio enabled in the form display ...
0
votes
1answer
336 views

ahah helper populate dependent dropdown

I am using the ahah helper as I couldn't seem to get my dropdown lists to depend on each other anyother way in Drupal 6. Below is my code, I can hard code the changes so that the second dropdown ...
0
votes
0answers
5 views

managed_file - get ajax_submit of Upload/Remove button

I have a managed_file form field. Is there a way to add more functionality to the Upload/Remove buttons of that field, like modifying the ajax_submit of these buttons? For example, if the Remove ...
1
vote
1answer
345 views

How to get parent node values on inline entity form hook alter?

I am using inline entity forms to create a paragraph in a node form. When I add a node I want the title of the node form to be copied to the paragraph when I click on "Add paragraph". I use ...
5
votes
2answers
3k views

How do I load a form with a specific form display (form mode)?

On a custom page I'm trying to load an user edit form with a specific form display. I'm able to load the form however I can't figure out how to load the form with the specific display. This is what I ...
0
votes
1answer
424 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'] = ...
-2
votes
1answer
23 views

Group of multiple fields + Language Based Setup Architecture

I have two different languages in the site, one is english another is finnish. Need an interface in the node add/edit like below, where user will able to add different set of items for each language. ...
0
votes
1answer
404 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 ...
0
votes
1answer
25 views

ConfirmFormBase to FormBase

Drupal 8.7.x I have a Form button with a confirmation page to delete an ingredient. I'm trying to convert it to a standard Form that just deletes it without confirmation, however I keep getting an ...
1
vote
2answers
1k views

How do I use $form_state['storage']['my_key']?

The question is clear from the title itself . I looked in the api specified in : https://www.drupal.org/node/2310411 . But it only mention to convert $storage = &$form_state['storage']; $...
0
votes
1answer
42 views

Custom formatter for paragraphs field

I want to build a custom formatter for a paragraphs field that renders some of the fields of the paragraph. However, I don't know how to access the single files of the paragraph field. So far I've ...
2
votes
1answer
391 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 ...
0
votes
2answers
350 views

How do I use an image CAPTCHA?

I am trying to show a CAPTCHA image in the form of my custom form, but it doesn't appear. Why doesn't this code show the CAPTCHA as expected? /** * Created by PhpStorm. * User: sony * Date: 28/02/...
1
vote
1answer
342 views

How to make select option works like a button?

I have created a contact form by using webform module, in that I have added one component as reset and the type is select options. My requirement is when I choose this reset option from that dropdown ...
0
votes
1answer
865 views

Display date picker not inline in Drupal 7 Forms API

I have installed Date Picker Module and it works fine. Below is the code: $form['date'] = array( '#title' => t('Select your birthdate'), '#type' => 'datepicker', '#date_format' =&...
1
vote
1answer
597 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, ...
0
votes
1answer
390 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
376 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 ...
0
votes
0answers
22 views

How to specifically define name and value attributes for checkboxes form element? [on hold]

I am trying to build a form parallel to an existing 3rd party html newsletter form (from CleverReach). The final checkbox markup needs to look like this: <input name="1130400[]" value="lorem ipsum"...
0
votes
1answer
22 views

Email misses fields from form [on hold]

This is regarding a Drupal 8 site, specifically Drupal 8.7.1 and the "Contact" module (with Contact Emails, Contact Storage enabled). The issue that I'm running into is some of the fields are not ...
1
vote
2answers
975 views

hook_field_widget_form_alter - modify specified field only

I'd like to use a hook to modify a widget, but only for a named field. Use case: a form has an entity reference to another context type, using an options_buttons widget (a list of available courses ...
0
votes
1answer
22 views

How can alter the select options provided by Simple hierarchical select?

Simple hierarchical select is used to display Taxonomy as a select field in my existing content type. So I'm trying to alter the value of it. Even tried using hook_form_alter but didn't work. So is ...
0
votes
1answer
374 views

Ajax Form Not Working in some Some Regions

I created an ajax based contact form in my module.Then I made a block view for the form. I tried putting that block to several regions. When I put the block to 'Sidebar Second' the form works as ...
4
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 ...
0
votes
2answers
462 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. ...
1
vote
1answer
421 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
0answers
35 views

Get the value of password confirmation field register

I want to use the default register form to get the value of the password confirmation field on register. If a user change his password it will call my API ans send the new information. I can't find ...
-1
votes
1answer
409 views

How do I output the content of a date (array)? [closed]

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? ...
1
vote
1answer
1k views

Submitting a form with ajax, when multiple instances of the same form are on a page

I am battling with D8 ajax right now, hoping someone can shed some light on where I'm badgering this implementation. The goal is to update a value based on the on the state of a checkbox. The issue ...
1
vote
2answers
543 views

How to create a new custom content type record when a user registers

My client's Drupal 7 website has a custom content type which is currently being used as a user profile. Now we need to incorporate this custom content type with the Drupal registration process. That ...
0
votes
1answer
446 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
244 views

Alter views exposed form

I have a view that in that view I set up 3 exposed filter, all working fine. I need to set a condition to show the third filter option to a specific user, it can be checked according to the user role, ...
1
vote
2answers
466 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 ['#...
2
votes
1answer
394 views

search block form not accepting special characters in drupal 7

If I search with any special character in drupal default search block form it returns error message like "You must include at least one positive keyword with characters or more.".after i do search ...
0
votes
1answer
618 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 ...
2
votes
1answer
416 views

How to use drupal_get_form outside of a menu

I am trying to use the drupal_get_form funtion outside of a menu and am not having any luck finding examples of how this is done. An overview of what I am trying to achieve is: 1) Pass control from ...
-1
votes
2answers
152 views

File upload form element that will allow the user to select files from server [closed]

I want to achieve (Create a form that will allow the user to select files from server) in Drupal 8.3 and have followed steps 1 to 4 but for some reason it's not working at my end. Can someone shed ...
0
votes
3answers
517 views

Styling label of a select list thorugh form API

I want to style the label of my select list with bold font and give it some color. This is the code for rendering form which I am using in a hook_block_view $form['dropdown_first'] = array( '#...
0
votes
1answer
390 views

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 ...
-2
votes
0answers
13 views

How to get Inline Entity Form Field prefix and suffix [closed]

I want to alter class of inline entity form field eg : field_author (inline_entity_reference) inside this -> field (title) field (body) field (image) i want add those field prefix to ...
0
votes
2answers
735 views

Form alteration is not working from within my form class

I am following https://www.drupal.org/docs/8/api/form-api/introduction-to-form-api for my hello world module. Below is my code namespace Drupal\hello_world\Form; use Drupal\Core\Form\FormBase; use ...
0
votes
1answer
409 views

User registration silently fails - how to debug?

On our Drupal 7 site, user registration silently fails. Drupal doesn't even reach the form's validation functions. What we checked: disabling javascript didn't help. Removing installed modules ...
0
votes
0answers
24 views

How to get the file ID using managed_file on custom form?

In Drupal 8, I have a custom form that I built using the Form API in a custom module. I am trying to upload a file using managed_file field. For some reason I can't get it to give me the file ID no ...
2
votes
1answer
425 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 ...
1
vote
1answer
389 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 ...
0
votes
1answer
417 views

ajax modified form drop down doesn't save

I have used form_alter to add a ajax callback to an element to my form. When the user chooses an option, it creates dropdown options for the other field. However, while this works fine for changing ...
0
votes
1answer
349 views

Checkboxes, Radios, 'select or other' wont render inside table select element

I want to render elements of type checkboxes or radios inside tableselect, but what I get are empty html tags. Textfield and select type elements render fine. Basically this renders fine. $...