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
1answer
416 views

Using 'return' with an ajax callback renders an entire page before my content is loaded

I'm developing a module that uses Openlayers maps and Drupal Commerce. When you click on the map, you should see products that relate to those coordinates of where you click. I have this working ...
2
votes
2answers
836 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
1answer
28 views

Form is not submitting after ajax callback

I have a form which has a checkboxes field. This field has an ajax callback attached $form['checkboxes'] = array( '#type' => 'checkboxes', '#title' => 'test', '#ajax' => array( '...
0
votes
0answers
34 views

Private file upload using core's contact module

I am using the core contact form module for user applications. I have set a private file upload directory in settings.php. When the user submits the application form I require them to also upload a CV ...
2
votes
1answer
5k views

How to create multi select list programmatically

How to create a multi select list in a custom module, populate values from taxonomy term and access the selected values when the form is submitted. I have to code below for multi select list. I want ...
2
votes
2answers
798 views

Node Add / Edit Options Vertical Tab Problem

For just one of my content types -- the built-in Article content type -- the node option vertical tabs at the bottom of the add / edit form are not displaying correctly. As shown in the attached ...
1
vote
2answers
775 views

How to add a confirmation form after the user clicks “Save” on a node edit form?

On a site I'm building, a user can edit certain fields on a node that cause a chain reaction to happen (which I've implemented using hook_nodeapi's "update" op). Since this chain reaction potentially ...
2
votes
2answers
1k views

Hierarchical select hook form alter

I have a problem with getting my module_form_alter to work for hierarchical select. I am running on Drupal 7 and my content type is called mytemp and I'm pretty sure my form-id is mytemp_node_form. I ...
1
vote
2answers
2k views

Multiple Field , same ajax callback

I created a custom field. The hook_field_widget_form has an submit element with an ajax callback: //Add more $element['add_zone'] = array( '#type' => 'submit', '#name' => $...
0
votes
2answers
843 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
1answer
606 views

Custom autocomplete form and autosubmit

I've added an autocomplete function for my views_exposed_form (a text input) using this tutorial and it works (https://www.linkedin.com/pulse/implementing-autocomplete-drupal-8-custom-callbacks-...
2
votes
2answers
989 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 ...
2
votes
2answers
766 views

form_set_error() redirects to raw ajax response page

I have a page with a simple view. Above the view there is a menu link that when clicked loads a node form with a required file field. The form is fetched and loaded using ajax_commands into a div on ...
0
votes
2answers
789 views

Can't insert data to database on form submit

I am trying to insert some datas into database table on form submit like this: function form_example_submit($form, &$form_state) { if ($form_state['values']['select']=='1') $gender = 'male'; ...
2
votes
1answer
918 views

Saving form fields on custom entity

I'm having problems saving my custom entity to the db. I created a custom entity called 'review' using hook_entity_info() with a custom controller. I have specified some parameters in the controller ...
0
votes
0answers
27 views

How do I pass values from a function to another while using form submission batch?

I am working on a custom module which processes a JSON file and downloads images from URLs in the JSON object, creates a new file entity, replaces the image URL in the JSON file with the file ID, and ...
1
vote
2answers
646 views

Value from ajaxified form field not passed to ajax callback

This is a continuation of this issue, where I couldn't get the ajax to fire on an entity reference field in a node edit form. With the following code, I'm able to get the ajax to fire. /** * ...
3
votes
1answer
1k views

“Uncaught TypeError: Cannot call method 'call' of undefined at 507 jquery.validate.js”

I am trying to implement clientside validation using the clientside validation model. I have been following the documentation located here. Specifically the Form API Section for Drupal 7. I believe I ...
3
votes
1answer
4k views

Add a link field to block form

I've created a module with a custom block that extends BlockBase. To the block form I added multiple textfields and select boxes, by simply specifying the formatter in the '#type' configuration. My ...
5
votes
1answer
1k views

Get the submitted values from $form_state

Is there a function (in Drupal 8) to build an array containing the submitted values in $form state? If I use $form_state->getValues(), I get more values than the ones I need.
7
votes
2answers
9k views

Add link field in custom form

I want add link field (label + url internal/external) in custom form This not work: $form['test_ink'] = array( '#type' => 'link', '#title' => $this->t('Link title'), '#url' => '', )...
1
vote
2answers
939 views

Creating 2 forms to work together on the same page for the same query

I'm facing trouble coming up with the following approach: I will have 3 separate forms acting on the same query from third party API's. On the front page there is a shorter quick-form that would ...
0
votes
1answer
30 views

How to disable form button on ajax callback?

I have a button with ajax callback and I want to disable it on button click without page reload. Preferably inside ajax_function but it's not obligatory. $form['my_button'] = [ '#type' => '...
2
votes
1answer
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
0answers
26 views

Why is wrong ajax callback function called?

I have two buttons $form['button_1'] = [ '#type' => 'button', '#value' => false, '#ajax' => [ 'callback' => '::ajax_submit_1', 'wrapper' => 'wrapper_1', ], '#...
0
votes
2answers
5k views

Display success message after submitting form

I am try to display an success message after submitting my form and redirect to next page. The code I am using is the following. public function submitForm(array &$form, FormStateInterface $...
0
votes
1answer
352 views

Webform 'Save draft' to send a mail with $sid

I am having a webform and I display the 'Save Draft' buttoan on the form. Once I click on the Save draft I need to save all the values in the DB (as it does on Submit event) and should send an e-mail ...
1
vote
1answer
45 views

Why ajax button calls submitForm?

I have no problems with using Ajax in every form element other then button. When I'm clicking this button '#type' => 'submit', '#ajax' => [ 'callback' => '::ajax_function', '...
0
votes
0answers
36 views

setErrorByName() not highlighting multi-select fields

I have the following HTML code, generated by drupal <div class="multiselect-selected"> <select multiple="multiple" name="field_test_ins[]" data-drupal-selector="edit-field-test-ins" aria-...
1
vote
1answer
25 views

Custom Validator on Custom Form

I see all kinds of examples of how to add a custom validator to an "existing form." Which means, you would use hook_form_alter. I want to add one in the code for my custom form. I'm adding this in ...
4
votes
1answer
1k views

Ajax pager with form callback

I created a form using the form api that outputs a list of results via an ajax callback. I want the said view to paginated. How can i do that? I'm using drupal 8 and don't want to use embeded views.
2
votes
3answers
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. ...
5
votes
4answers
3k views

tableselect with dropdown per row

I use a tableselect to output a list of terms and per row I want a drop down (select): $header = array( 'name' => array('data' => t('Name')), 'weight' => array('data' => t('...
0
votes
2answers
27 views

Hide one form element until another is selected

Is there any way to disable the field 'model_article_nr' until 'model' is selected this is what i have and as it is now i can select 'model_article_nr' before i have choosen a model which leads to ...
0
votes
1answer
405 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
2answers
851 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'), '#...
0
votes
0answers
63 views

How can I override the form-element-label.html.twig template?

In a view, I have checkboxes displayed using the better-exposed filter. Ajax setting is true. Currently, there is no template suggestion for overriding form-element-label.html.twig. Somehow by adding ...
0
votes
0answers
13 views

How to target daterange field in form alter?

I have a date range field in my exposed filter and I want to add a class on it. The problem is that I can't target it despite I can do it for the rest of the field of the form.How can I achieve that? ...
2
votes
1answer
1k views

Customized User Registration form with Profile fields

I'm missing something core to how user registration forms are customized and the data is added to the database and I'm hoping to get a workflow. I have created about a dozen Profile fields, textareas,...
0
votes
1answer
1k views

Trigger ajax callback from input field webform

I have a form build with the webform module. When text is entered in the input box in this case webform component 2 I want it to execute a ajax function and put data in a div. However this is not ...
0
votes
1answer
350 views

How to make uploaded file permanent to node without node submit

My module automatically save new empty node when user create new node and redirect to edit this node. Now, is it possible to make uploaded file on _node_edit form without submitting form? edit: When ...
4
votes
2answers
3k 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....
1
vote
2answers
2k views

Entity form with pre-populated entity reference from URL

I have two entities which are in a parent/child relationship. Now I want to add a operations link in the parent's list view so that I can show the child's entity form with the reference to the parent ...
1
vote
1answer
34 views

Table in custom form + empty values in form_state

In a custom form I created a table element: // Table results. $form['table'] = [ '#type' => 'table', '#header' => $header, '#rows' => $rows, '#attributes' => ['id' =&...
0
votes
1answer
2k views

Skipping form validation with a custom action button

Related to my previous question -- I've got the button added to the form properly (thanks googletorp!), but now I'm having separate validation issues beyond just adding the button. I have added a "...
2
votes
2answers
916 views

add css if url contains

I have one node type and two page types for this node. http://site.com/themes/* and http://site.com/years/* And i want to hide one of the "view-filed" in all "years" pages using the css. Found ...
0
votes
1answer
408 views

How can I remove “please wait…” from a form?

I saw this Remove the "Please wait" text on Ajax Call but I can't find the form element. <?php dsm($form);?> and <?php dpm($form);?> return errors. This is what I found in $node: ...
2
votes
2answers
368 views

Configuring mail function in multistep form submit in drupal

I have been working in a multistep customer-survey form and i am unable to configure and send mail after the form is successfully submitted. Here's is code for submit handler, function ...
4
votes
1answer
856 views

How to set a default value for Simple hierarchical select?

I tried to implement hook_form_alter in order to pass default value to Simple hierarhical select views exposed filter. function mymodule_form_alter(&$form, &$form_state, $form_id) { $tid = ...
0
votes
2answers
49 views

Ajax validation only works when I am logged in as an administrator

I have created a custom contact form and I have set up an ajax inline validation. My form works very well. But Ajax validation only works when I am connected. When I am not logged in as an ...