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
0answers
7 views

How many different ways are there to create a “page” in Drupal 8?

By page I mean what's served by a given route/url. Trying to understand all the options so I know what I can combine (e.g. create a View, and use a render alter hook to add a form at the bottom). ...
0
votes
1answer
27 views

Programmatically auto-submit a Webform after visiting its URL

I am wondering whether it's possible to programmatically auto-submit a Webform after visiting its URL and to save the user from a 'submit' button click. The below webform can be accessed via /form/my-...
1
vote
2answers
2k views

Get $form_state values from individual entity form fields

I have a weird use case. I created a custom form with some fields and I added some other fields from one entity form like this: public function buildForm(array $form, FormStateInterface $form_state) {...
0
votes
1answer
8 views

How to use a token in the reference fields

1-I have a node with the name of the project. 2-this node has a project_name field that generates by these Tokens 3- I have a reference field that it load an entity type in the project create the ...
2
votes
1answer
785 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
22 views

How to serialize a form's render array to json in Drupal 8?

I want to build a REST resource to return Forms as JSON with all labels, help text, default values, etc... When I use REST's built-in resource /entity/entity_form_display/node.article.default it does ...
0
votes
2answers
757 views

Submit button to filter data from table select by selecting on list select

i'm new on drupal, i've create a module that shows a form (with tableselect, list select and a submit button) the tableselect shows data from the database, but i want to filter what i want to see on ...
0
votes
3answers
911 views

Setting field value's according to user input in a custom form?

i am using FAPI to create nodes through a custom form. the code below creates the nodes and assign them with a title and a body, so if i wanted static field values everything was perfect. my problem ...
0
votes
1answer
858 views

The “Remove” button is not working

I'm using a "managed file" to upload an image, which works fine, but if you want to remove the image by clicking on the "Remove" button, nothing happens. $form['logo'] = array( '#type' => '...
0
votes
2answers
924 views

Problem adding button to custom content type form

I am trying to add a cancel button to a custom content type form (typename/type/add). I have looked around and there seems to be two main ways of doing this: Creating a template file with the name ...
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('...
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
1answer
27 views

Remove an item from $form_state in an ajax callback

I'm using this form api example: AjaxAddMore. I want to add a "remove button" for each indiviaul element, in order to remove an item but not the latest. Thouse are my changes: ... $form['...
2
votes
2answers
781 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
24 views

Prevent form regeneration when a callback function is called through ajax

Here is the code for the custom form with a field(field_B) that calls an function through ajax. The issue is that I want the function (MY_MODULE_XYZ_function()) to be executed only once, when the ...
1
vote
0answers
25 views

How to prepopulate a field from parent form to Inline Entity Form

I have 2 content types - Employee and Project. Both forms have Inline Entity Forms with references to content of each other when user creates an Employee node, he can add projects he took part in, ...
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 ...
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
12 views

Validating Tableselect: Checkbox

I have a form in which i have created a table like the following $form['tableselect_phone'] = array( '#type' => 'tableselect', '#header' => $header, '#options' => $options, '#...
2
votes
2answers
742 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 ...
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 ...
0
votes
0answers
45 views

How to have a button to open a modal popup from a table form?

I have a custom entity (contract_subscription) created in a custom module (amap) by a bunch of BaseFieldDefinition, one of which being a file field: $fields['file'] = BaseFieldDefinition::create('...
0
votes
2answers
84 views

Adding a view to node edit form

How to attach programmatically a view to the edit node form in Drupal 8? In D7 I could achieve this by using this code /** * Implements of hook_form_alter(). */ function MYMODULE_form_alter(&$...
2
votes
4answers
2k views

Inserting a view in node edit form

In a node edit form i want to display an editable view, so an author can not only edit the node itself but also can alter some values of other nodes represented by the view, which is editable via the ...
2
votes
2answers
840 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
373 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
3answers
349 views

How to get the product id on hook form alter

I am currently working on drupal 8 commerce. I need to form alter some of the expose fields but need to get the product id first so I can get my condition on the product fields. I used this kint($...
1
vote
2answers
802 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'), '#...
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....
0
votes
1answer
1k 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 "...
5
votes
1answer
1k views

Creating date field with only month and year

We are using the form API in a custom module (and not an entity field), how can we easily set the date widget for just year and month data entry. I've tried adding a #date_format attribute but no ...
0
votes
2answers
18 views

Start with multiple entity reference items

In Drupal 8, I have created an entity reference to an "author" taxonomy on a content type. The form display settings are set to autocomplete. By default it starts with one field and you can click "Add ...
0
votes
0answers
19 views

Programmatically create master/detail forms

I want to create a master/detail form in my custom module using form api and ajax. I have three content types: CT1, CT2 and CT3. CT1 is the master, and CT2 and CT3 are details of CT1 (they have a ...
0
votes
1answer
12 views

Form #after_build is not working for PHP 7x

I'm using #after_build in one of my custom module form like follows $form['profile_image'] = array ( '#type' => 'managed_file', '#after_build' => array("change_pic"), ); and the ...
-1
votes
0answers
11 views

How to filter the select list of an term entity reference field through another field with its parent term

I have created groups, where the visibility of menu items can be configured in the group as a term entity reference field. The terms can have multiple parent terms. I want user of the form to be ...
14
votes
3answers
29k 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(). ...
4
votes
1answer
1k views

Alter granularity in date exposed filter from Y-m to Y if only year is selected

I am trying desperately to get the following working: Goal: I have a views that displays a list of events. To this views is a date exposed filter attached, with granularity Y-m(year month). I want ...
0
votes
2answers
3k 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
0answers
23 views

Use autocomplete with an infinite cardinality

I am trying to attach a list of users to a new entity I am creating. I want to enable autocomplete on those fields but I can't get it to work. For the moment, my field looks like this : array( ...
0
votes
0answers
14 views

Vertical Tabs: Wrapper problem

I have a form with several fieldsets and i am thinking about adding a vertical tabs form field to turn the current fieldset to vertical tabs but i use a lot of AJAX in the fieldsets. The AJAX elements ...
3
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.
0
votes
1answer
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
0answers
15 views

Unexplained (buggy?) behavior of drupal_process_states with checkboxes in Drupal 7

I have 3 checkboxes named A, B, C. My desired behavior is as follows: if, and only if, both A and B are unchecked, then C becomes checked. Inversely, if either A or B are checked, C becomes unchecked. ...
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,...
1
vote
4answers
764 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....
0
votes
1answer
671 views

Save checkboxes value into another checkbox field

I'd like to save the value of a checkboxes field which is link to a product once I save my content type. I've created the code needed to create the product and the node. When the node is in creation ...
0
votes
0answers
33 views

Adding AJAX to an existing form element?

I am trying to Ajaxify a node form element (field_unterbringung). When the user changes the value of an entity reference field (unterbringung) the markup should change from "old markup" to "new markup"...
0
votes
0answers
20 views

Disable browser auto-complete/auto-fill for username and password form fields?

I have a custom username and password field in my form which is independent from the normal website login. public function getFormFieldUsername() { return [ '#type' => 'textfield', '#...
1
vote
2answers
902 views

Webform Custom-Field Module and validation

I am currently working on a Webform that is used to enter some rather complex finance information (think tables with sums and other weird checks). Since the styling has to be rather specific for this ...
1
vote
2answers
717 views

Change the file field description

How can i change the file field description without hacking a contrib module like the file.field.inc file ? this is the function i would like to modify: theme_file_upload_help