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

How can I use a content type field on the body of the e-mail message template on the Webform module?

For usability matters, I would like to let the editor create his own confirmation message on my Event content type. So I create a field for that. I also have another field to select which webform is ...
0
votes
0answers
20 views

Validation after all other validations were successful

I have a form with several form fields and two validation handlers. function my_module_my_form_validate_integer($element, &$form_state) { // validation stuff } function ...
0
votes
1answer
10 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 ...
0
votes
1answer
100 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-...
0
votes
0answers
32 views

How to serialize a form's render array to JSON

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 ...
1
vote
0answers
27 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
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, '#...
1
vote
2answers
25 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 ...
0
votes
1answer
28 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['...
0
votes
0answers
20 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
13 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 ...
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 ...
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. ...
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
22 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', '#...
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('...
-2
votes
1answer
25 views

after 8.6.14 set entity reference field via form alter failed

after the core update some how the form alter set field was broken, I tried multiple methods but its not working like : $form['field_trip_reference']['widget']['#default_value'] = array(820); $...
0
votes
0answers
15 views

AJAX select field - $form_state not saved

SOLVED (see comments) I have a form with a select field (where you can select a title of a novel). This select field automatically writes a the respective ISBN of the novel into a textfield when a ...
0
votes
0answers
17 views

Inline Entity Form hook_alter causes Ajax error on 'Add another' button

I created the module to hide some fields in my Inline Entity form. Although it works I faced the problem. I need to add multiple custom content nodes with Inline Entity Form. When my field setting ...
0
votes
0answers
22 views

Dynamically set '#prefix' => '<div id=“wrapper_id”>'

I have a form with a select field (where you can select a title of a novel). This select field automatically writes a value (the rspective ISBN of the novel) into a textfield when a novel is chosen by ...
0
votes
0answers
18 views

How to restrict dates in the form widget?

I am attempting an upgrade and I am looking for something that mirrors the functionality of the Date Restrictions module Basically, I used it to set relative limits,, something like no earlier than ...
1
vote
1answer
26 views

Modify existing custom content form

I'm very new to Drupal development and I am completely stuck(. I have a custom content form, where I need to hide some fields in Inline Entity Form. I am trying to write my own custom module to ...
0
votes
0answers
15 views

Displaying input fields on a panel

Is it possible to display the input fields on a Panel so that users can input data into them? I currently have these fields set up on my content types but would much prefer them on a panel. I've ...
0
votes
0answers
17 views

Overriding values in AJAX dynamic form fields

I built a form based on that documentation page: https://api.drupal.org/api/examples/form_api_example%21src%21Form%21AjaxAddMore.php/class/AjaxAddMore/8.x-1.x of course I extended that form because I ...
0
votes
0answers
22 views

Replace select options

I have a form: public function buildForm(array $form, FormStateInterface $form_state) { // Disable caching on this form. $form_state->setCached(FALSE); $scheme_data; // code to ...
0
votes
0answers
43 views

How to disable browser autocomplete for the login form

I would like to remove auto fill user name and password while login or forgot password. I have tried this but its not working: if ($form_id == 'user-login-form') { $form['name']['#attributes']['...
1
vote
1answer
27 views

Error when I try to call a form

Here is my class: <?php namespace Drupal\mais\Form; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Ajax\AjaxResponse; use Drupal\Core\Ajax\...
1
vote
0answers
45 views

How do I override the registration form?

I am trying to override the user registration form in Drupal 8, using the following code. RouteSubscriber.php namespace Drupal\registration_subscription\Routing; use Drupal\Core\Routing\...
-1
votes
1answer
55 views

How to transfer data from/with PrivateTempStore? [closed]

I have an multistepform which handles sessions and stores like this: https://www.sitepoint.com/how-to-build-multi-step-forms-in-drupal-8/ But i want the option that the user can login in between. The ...
0
votes
1answer
25 views

Get Field Name Being Deleted From Configuration Updates/Delete Form

Trying to get the field_name being deleted when viewing a route like entity.field_config.user_field_delete_form. Example path: /admin/config/people/accounts/fields/user.user.field_name/delete Some ...
1
vote
1answer
36 views

How to get a field third party settings for every content entity forms

Can someone explain or post an example of how to get a third party field settings on every content entity forms? I'm looking for a generic code where a form can be customized (like calling a custom ...
1
vote
2answers
57 views

Download file programmatically

I have a custom module where I need to create a file and download it on form submission. So far, I managed to created the file and save it in public folder, but I cannot find a way to download it to ...
1
vote
0answers
21 views

Drupal won't update textfield from a integer value with no decimal to the same value with a .0 decimal

I am facing a strange situation in Drupal 8 where the value of a text field won't be updated in some situations. Indeed, if the textfield's value is an integer, for instance 19 and I try to update ...
2
votes
1answer
45 views

No default value for '#type' => 'date'?

is there a way to configure a date form so it has no default value? Setting the default value to NULL sets the default value automatically to the current date. /** * @return array */ public ...
0
votes
1answer
11 views

Disable (or workaround) form rebuild with managed_file field

I'm using the Form API to create a custom form. It has a managed_file field and some other fields, some of which are required. If any of the required fields are not filled in, the file upload for the ...
1
vote
1answer
43 views

Select list set default value does not work

I have referenced filed, which works like select list, I want first value be always default value in content edit page. Now N/A is always selected. function theme_form_alter(&$form, \Drupal\Core\...
0
votes
0answers
23 views

Missing values in $form_state['values'] when addding field through _form_alter after AJAX callback

I want to add a couple of fields to a content type form using AJAX and, upon validation, run a custom _submit callback to do something with those fields. My approach: 1. Alter the form adding a ...
0
votes
0answers
21 views

Get data from textfield dynamically in form

I would like to get data from textfield dynamically. Next i want to verify content from field and do sth(without refresh) $form['cont_but']['scan_field'] = array( '#title' => 'Scan:'...
0
votes
0answers
14 views

D8: Embedding View in custom form with exposed filters causes custom submit not to fire

I am trying to embed a View into a custom form which has exposed filters. However when I add the field, it causes my custom submit button not to fire at all. It doesn't even try to reload the page. ...
0
votes
0answers
34 views

Error Passing Function from Form Controller Across Module

I would like to access a function from my Form\Form.php in both my Plugin\Block\Block.php and MYMODULE.module. Related: How to render content generated by controller in custom block? and Inject ...
0
votes
0answers
11 views

Using nested #states with 'visible' causes problems

I have a form with 3 radio fields and a textfield in it. Radio Field 1,Radio Field 2,Radio Field 3 and Textfield I'm using #states to make: Radio Field 2 only visible if certain input from Radio ...
1
vote
1answer
48 views

AJAX button - HTML in #value causes problems

i have an Ajax button, the code looks like this: class coolButtons { public function getFormFieldAjaxButton() { return [ '#type' => 'submit', '#value' => t('<i class=" ...
0
votes
1answer
17 views

How to remove the click event on an Ajaxified form's submit buttons?

I've created several forms with Drupal 8 directly in admin or with Form API. I've added some client side validation with this jQuery plugin : jQuery Validation Plugin. Everything works very well. Now ...
0
votes
1answer
28 views

Custom Save and Unpublished button for node

While clicking Save as draft button, it will save the node but while it have to redirect to the created node it gives error The website encountered an unexpected error. Please try again later. and $...
1
vote
1answer
28 views

How to style a custom theme setting form

I have a set of custom theme settings defined in my theme. They are fully integrated into my theme and appear on the theme's setting page but they are not styled. I use the seven admin theme. I ...
0
votes
1answer
31 views

How to use custom code to change the node form layout and group fields while maintaining values?

I am trying to alter the node form layout in a form alter hook. I altered the node form and added a field set in which I grouped couple of existing fields into a fieldset. Then hid the existing ...
0
votes
1answer
53 views

Unique form per user with custom form class

Not sure if this is a related/duplicate of Generate unique form ID based on context I am hoping I can render a unique form per user with the Form API using a custom form class. What I've seen with \...
0
votes
1answer
79 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. ...