Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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

how to add checkbox value as json data

I have created a custom module for a form. And I have json data which I want to add as checkbox values. $request = drupal_http_request($url); $jsonarray =drupal_json_decode($request->data); ...
0 votes
1 answer
862 views

How to fix error Undefined index: parent in taxonomy_form_term_submit()?

I got below error on my site recently. Notice: Undefined index: parent in taxonomy_form_term_submit() (line 829 of /var/www/Sites/xxxxx/modules/taxonomy/taxonomy.admin.inc). I google it and find ...
2 votes
2 answers
2k views

Trigger jQuery "add more" multiple times

I have a form that I am filling with default values in hook_form_alter. Some of the fields are in a in a field group and I need to trigger the "add more" button using code. I figured out how to send ...
0 votes
1 answer
797 views

Form Validation. Ensure Placeholder is not submitted value

I have a Drupal registration form with a placeholder set on a first name field. I am trying to get the form to check so that if the placeholder value is the same as the submitted value it will give an ...
1 vote
1 answer
588 views

setErrorByName not working properly if field is in #details

In a form, some fields are defined in '#details': $form['person2'] = [ '#type' => 'details', '#title' => t('Person2'), ]; $form['person2']['lastname2'] = [ '#type' => 'textfield', '#...
0 votes
1 answer
2k views

Adding #ajax callbacks to form elements in HOOK_form_alter()

I'm trying to add an #ajax callback to a select element on a form that is created in another module on a Drupal 8.x site. When I add the #ajax callback using HOOK_form_alter() in my module, the Ajax ...
3 votes
3 answers
2k views

Dynamically add input field using #ajax

As the question says, im not clear on how to go about adding new input fields depending on values of certain fields in the form. I got as far as setting a callback and a wrapper, but i just can't ...
0 votes
1 answer
652 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 ...
1 vote
1 answer
420 views

Pre-Populating a Form Field with something other than its default value

I'm having a strange problem. I am constructing a form with checkboxes to toggle email subscription preferences on and off. For the new user sign-up form, this is straightforward: $form['marketing-...
0 votes
1 answer
50 views

Submitting an existing block or form in a modal doesn't work

I am trying to open either the simplenews subsription block or the corresponding form in a modal. I tried with both the form using the formBuilder service or the exising plugin-block and in both cases ...
0 votes
1 answer
571 views

Redirect after user creation via form

What would be the proper hook to redirect after the user registration form is submitted and is in valid state? I'm trying to automatically create a certain content-type node when a user registers and ...
1 vote
1 answer
491 views

How to wrap / manipulate element outputs on a form's checkboxes html?

I have the following form that contains a big list of checkboxes. The first checkbox is the parent of the children below it. In my case it is called "Africa" and the ones below it are "Africa-child" ...
1 vote
2 answers
693 views

How can I add a field in Entityform / hook_form_alter

I'm trying to add a field to the form in hook_form_alter. What's the proper way of adding fields in this hook in case of entityform? I tried to add it this way: $form['leadname'] = array( '#type'...
0 votes
2 answers
596 views

Adding checkbox in admin table display

I'm trying to add a checkbox column in the admin table part of my module. The idea is to add checkboxes at the beginning of each row, like in the normal admin content management form. My table is ...
1 vote
1 answer
3k views

How to retrieve a select box option and set the field's value to it?

I have a a taxonomy term select box (called "product_keyword") in a node that gets its options populated via the Reference Field Option Limit module. There are 3 other taxonomy term reference fields ...
0 votes
0 answers
9 views

Delete image from form after invalidated

I made a custom hook_alter_form to invalidate and delete a image if invalid. php code in the .module file <?php /** * Implements hook_form_alter() to add custom validation for image ratio. */ ...
0 votes
2 answers
2k views

Altering Views Exposed Form Elements and their Associated Labels

I have a series of Views Exposed Forms across a Drupal 8 website. My goal is to generate unique template suggestions so I can theme each individual input and their labels differently as needed. Here ...
1 vote
1 answer
708 views

The login form isn't rendered

I am newbie to drupal. Recently I changed blocks of my theme and set main page content block to none.I logged out of my site. I tried to access admin panel by appending /user at URL. It redirected to ...
2 votes
1 answer
2k views

Upload a file by Ajax without submitting the form

I want to upload a file by Ajax (without submitting the form) than process in backend, and clear the field to allow to add another file. Is it possible with Drupal 8? Can anyone provide an example? I ...
0 votes
1 answer
554 views

How to use ajax callback on auto complete field inside a block settings form?

public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); $selected = 'value of a field'; $form['node'] = [ '#type' => '...
2 votes
1 answer
1k views

problem using ajax callback in form

I have a very simple form that has a select box of the terms in a vocabulary, and renders the selected term below it. It seems that the first time I change the value in the select it renders the ...
0 votes
1 answer
2k views

Making text fields autocomplete in views exposed filters

I want to make a text field auto complete in a views exposed form. I tried using the following code but nothing happens(I don't see that blue icon in the text field): <?php function nk_menu() { ...
0 votes
1 answer
884 views

Conflict between ajax callback and jQuery UI dialog

I have a button that triggers an AJAX callback with the form api like so : $form['show_modal'] = array( '#type' => 'submit', '#value' => t('Some crazy text'), '#ajax' => array( '...
0 votes
1 answer
674 views

how to save checkboxes values in node programmatically

i want to save checkboxes values in entity reference checkboxes field with node_save : $form['wrapperrr']['id_offre'] = array( '#title' => t('Liste des Offres'), '#type' => '...
4 votes
2 answers
4k views

How to trigger a form and pass variables to $form_state with jQuery?

What is the way to trigger a Drupal form via JavaScript, and pass new values to $form_state while doing so? I have a main form, which has an element that triggers a jQuery UI dialog with a form in it. ...
2 votes
2 answers
1k views

Ajaxly set Text Field Value with Drupal Forms API

I have a text field and a ajaxified link in my form: $form['id_number'] = array( '#title' => t('ID Number'), '#type' => 'textfield', //textfield '#suffix' => '<div>l(t('...
0 votes
2 answers
1k views

Boolean checkbox in sytems_settings_form

I have written the following code $form['checking'] = array( '#type' => 'checkbox', '#default_value' => variable_get('checking',0), '#title' => t('title'), '#required' => ...
2 votes
2 answers
8k views

How to add a javascript function after uploading file

I make a form using FAPI, and this form contains a file managed field. I want to show an alert after uploading the file ("uploaded successfully"), and a confirmation ("Are you sure you want to delete ...
0 votes
2 answers
991 views

How do I add tabledrag with 'weight' to admin form

I have built a fairly basic module but i'm struggling with the UX of the admin form. Essentially I need a list of items that have several values; a textfield, checkbox, select list and a button to ...
0 votes
1 answer
788 views

Ajax Callback to Update Select List not Working

I have defined couple of fields inside my custom entity basefielddefinitions() like so... $fields['product_line'] = BaseFieldDefinition::create('entity_reference')... $fields['product'] = ...
0 votes
3 answers
2k 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 ...
1 vote
2 answers
1k views

form_get_errors() is NULL when calling it in an AJAX form callback

I have a form with a bunch of required fields that all have the same callback. Here's a single field example: $form['name'] = array( '#type' => 'textfield', '#title' => t('Name'), '#...
2 votes
2 answers
548 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
0 answers
50 views

How add a cache context in a form_alter?

I'm on Drupal 10.2.x. I'm writing a form_alter for a node add/edit form, where I am putting some extra markup data depending on terms of a vocabulary licenses. function my_module_form_alter(&$form,...
1 vote
1 answer
581 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 ...
2 votes
1 answer
1k views

Reset button for an AJAX form

How do i programatically reset the values of an AJAX submitted form for Drupal 8? I Want to reset them with an AJAX callback. Here is my current callback. It works because i'm forcing the values to ...
1 vote
1 answer
417 views

How do I configure the route to the add form for a content type created as a bundle class?

I've got a custom content entity type, created for me by drush generate and I'm extending that using bundle classes. I've got a MyContentType class and a MyBundle class that extends it and provides ...
1 vote
1 answer
75 views

How override theme for a node add\edit form?

I'm on D10.2.x. My site uses Gin as back-end theme but also as fallback front-end, being decoupled and having to "front-end page" actually shown via Drupal. I'd want to override the default ...
3 votes
1 answer
441 views

Vertical Tabs in Panel Pages

I am trying to have three forms available to the public on my site and would love to have them configured in in the vertical tabs layout. Initially I was going to have them available through node/add/...
0 votes
3 answers
1k views

How can I change the default system message shown on form submission

I've created a business card request form as an EntityForm and am scratching my head trying to figure out where in the module i can find the line - ( " The submission has been saved " ) . This ...
1 vote
1 answer
523 views

how to get all options values of simple hierarchical select in drupal $form?

i have writed this code to unset empty terms : function shs_selective_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'views_exposed_form' && $form['#id'] == '...
0 votes
1 answer
516 views

Content type not responding to AJAX callback

I am using a ctools content type plugins to render a custom form that will have only one submit button. The submitbutton will switch an eck entity field (boolean) from 0 to 1 and back (if pressed ...
1 vote
1 answer
419 views

How can I clear all check boxes on failed validation?

I have form with check boxes. The user checks the boxes and hits the submit button. If validation fails an error message is displayed. I also want all of the user's checks to be cleared so they can ...
0 votes
1 answer
1k views

How to programmatically render a webform to display specific Elements

I have tried this way but not able to hide "confirmation_id" element. public function buildForm(array $form, FormStateInterface $form_state, $sid = NULL) { $my_webform_machinename = 'request_form'; $...
1 vote
1 answer
396 views

Adding a validation step via hook_form_FORM_ID_alter()

I am trying to add a custom validation function to an existing form. I am using hook_form_FORM_ID_alter() to edit the form. I am then adding a new function to the #validation array. When I use dpm() ...
11 votes
7 answers
23k views

How can I add a class to a label?

I need to add a class name to certain labels created by Drupal's form API like this: $form['name'] => array( '#type' => 'textfield', '#title' => 'Prénom' ); If I use the following, the &...
2 votes
1 answer
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 ...
2 votes
1 answer
2k views

Autocomplete textfield displays value when selected and not label

I have a textfield autocomplete field that shows a list of full user names and email addresses as designed but when a user is selected, the user id is displayed in the field; not the name and email ...
1 vote
3 answers
2k views

Controlling a dependent field in a multi-instance paragraph

The fields below are part of the node/add node/edit forms of my custom node type. The paragraph field_para_city contain one field_city. (I later need to add other fields in the paragraph). The user ...
1 vote
4 answers
1k views

Create duplicate registration form with extra fields

I have a site built using Drupal 7. The site has a registration form now. There is a new requirement to add a couple of new fields in the registration form and put it in a new page. http://example....

1
2 3 4 5
137