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

Rendering the Layout Builder form in a controller

I'm trying to render a Node's Layout Builder Override form in a custom controller, but I'm having issues rendering the entity form. I basically want to have the Node's layout builder on it's own page. ...
2
votes
0answers
29 views

What is correct way to override the field required error messages on custom form?

I have installed clientside validation contributed module in my Drupal 8 Project. Now all client side validations are looking uniformed throughout the site. The only issue I am facing right now is ...
1
vote
1answer
22 views

How to print rest of the form using “without” function in twig while printing custom user field present account array?

I am writing custom template to style my "edit user profile" form page. Below is the code in twig file : {{ form.first_name }} {{ form.last_name }} {{ form.account.mail }} {{ form.account....
0
votes
0answers
17 views

How to display register forms in the form of tabs?

I have two registration pages register_one and register_two. I used the multiple_registration module for creating register forms. Now I want to display two register forms in the same page in the form ...
0
votes
0answers
14 views

Scenario for validation in two submit times ( the second one validates and shows a previous hidden field)

I'm using alter_form to change 'user_login_form'. The problem is that i'm hidding a field and i want to show it to the user and validate it ONLY AFTER login and pass are validated ( user has done a ...
0
votes
1answer
14 views

Send view field in URL - Drupal

I have a search page created with embedded filters in Drupal 8 View. In the list of fields I have a fields - [Field_program_id]. I also have a button 'Learn more' when clicking this button I want to ...
0
votes
0answers
23 views

How to dump $form in twig template of custom form?

I am trying to debug $form values on twig template, created for rendering user edit form in my own way but when I am trying to use {{ dump(form) }} or {{ dump($form) }} browser hangs and then system. ...
0
votes
0answers
33 views

How to let users remove a specific field or fieldset on a custom form using the form api?

I followed this Drupal example: https://git.drupalcode.org/project/examples/blob/8.x-1.x/form_api_example/src/Form/AjaxAddMore.php I've edited the code a bit to use fieldsets instead of just one ...
1
vote
0answers
14 views

Customizing the checkout form

I need to fill Billing Info form with data that the user has filled in another page of my commerce site. I've made a hook_form_alter with the following weird code (with the help of kint): function ...
1
vote
0answers
25 views

Hook form alter not working for node edit form

I have a content type called landing_page. If I edit an existing node in the admin /node/31/edit and I inspect the form I see id="node-landing-page-edit-form". I can't get it to work to use ...
0
votes
0answers
20 views

Field gets unset and fails validation in user edit form

We have a special date field that we set upon user creation when our custom user form is submitted. The user does not have to set this field themselves. We have a separate form, which is a user edit ...
0
votes
1answer
40 views

Drupal 7 Form API - AJAX updates for multiple file uploads

I have a Drupal 7 custom module form that uploads then processes multiple images. I have an ajax callback that updates page content with the processed images. BUT, the page update happens when all ...
1
vote
2answers
26 views

Drupal 8: how to generate options based on Ajax callback

In Drupal 8, I want to generate options of second select-box based on Ajax call of first select-box. The result generate a third new select box but I don't need to generate a new one. I want to ...
0
votes
0answers
34 views

How to inject a service into a callback in ajax form? [closed]

I can't access to my injected service from inside a form #ajax callback method : this is the form element that triggers the #ajax callback ( which is an external class method): /src/Form/...
0
votes
0answers
47 views

Show admin field based on field value

In the admin of a certain Content type (node/31/edit), I Added a select list field field_hero with two key|value's: carousel|Carousel video|Video when the site editor select carousel, I want to ...
0
votes
1answer
26 views

Handling data from form in modal dialog

I'm building a tool that contains a few clickable regions. Each region has a link with class="use-ajax" data-dialog-type="modal" pointing at a custom form route. Everything is working great and I'm ...
1
vote
2answers
37 views

Using #states in a form with checkboxes

I would like when a client check one of the checkboxes, a text field appeares. Example: if he clicks on 3 checkboxes, all the textfields of the 3 show off. My #checkboxes : $form['input']['...
0
votes
1answer
26 views

How to add Jquery Validation to Custom form and set error to field?

I want to implement client side validation using jQuery on my custom form. I have enabled clientside validation contributed module I have successfully attached custom js file using following code: ...
0
votes
1answer
33 views

How to save entity from a ajax form

I'm running Drupal 8.8.x The Problem Entity is not being saved when form is submitted through AJAX. Example: Build Form public function buildForm(array $form, FormStateInterface $form_state, ...
0
votes
0answers
6 views

Adding a new field to the layout_builder_update_block/layout_builder_add_block for a view block for usage later

We are using layout builder for adding view blocks to node pages. I need to modify the "add/update" form with a new boolean field (checkbox), and use the results that are stored (true/false) later on ...
0
votes
1answer
61 views

How can I get the currently submitted form state in a block on the same page?

How can I retrieve the currently submitted and validated form state? Please assume the following scenario. A page has a form on it created using the form API. The data in the submitted form is ...
-1
votes
0answers
64 views

empty_option value after form submission (field 'select'; field value depends on other selection)

I'm trying to save form data to the database. The form consists of two fields (select). The values of the second one are dependent on the values of the first (ajax callback). I also added #...
0
votes
1answer
17 views

Second managed_file upload field fails with “An unrecoverable error occurred”

I have a form with two (ajax enabled) upload fields. Submitting a file to the first one works, then submitting a file to the 2nd does not, giving An unrecoverable error occurred. The uploaded ...
0
votes
1answer
42 views

Why I am not able to add custom validate Handler function for UserPasswordResetForm on form_alter?

I am trying to override default reset password functionality by using hook_form_FORM_ID_alter as below: The below code is written in custom module called usr_registration.module file /** * ...
0
votes
1answer
27 views

MachineName field element: How do I use the source and exists properties?

In my custom form, I am trying to create webform entities. Since webforms need unique machine names, I'm using the MachineName (machine_name) form element. The D8 MachineName element documentation ...
0
votes
1answer
42 views

Enable a button basing on multiple form values being equal

I would not like users to be able to submit a form until: All fields are filled out The password and confirm password fields are equal I can do this with JavaScript, potentially, but then the ...
-4
votes
1answer
25 views

How do you build a conditional form?

How do I build a form with : optgroup select for subject conditional display of informations depending on the selected subject conditional display of a part of the form if a checkbox is ticked ...
0
votes
0answers
16 views

Dynamic field by ajax callback is not added to form [duplicate]

I have a form where I create a new field when an input field has been filled out. I do this with ajax callback that seems to work partly. The field is being rendered but it doesn't get all the ...
0
votes
0answers
30 views

How can I upload an image in a custom form and save the result in a custom database table?

I have a custom form and I want to store the values in a custom database table. After submitting the form, the first_name and email_address fields are successfully saved to the database, but image ...
0
votes
0answers
15 views

Change the form value and submit the form in a single ajax call

I have two select fields in the form. The values of the second select field depend on the first one. When I change the first select field, I need to change the options of the second select field and ...
0
votes
1answer
27 views

How to customise list (text) field?

On my user registration page, I would like to add a field where users can type in and select specific key words. It is possible to make such a field using webforms. It would look as below: However, ...
0
votes
1answer
33 views

How do you add help text to a form item?

I would like to change the help text for an input field. My form ID is views-exposed-form-events-page-1. I have a text field that I want the helpful hint to appear below. The field ID is edit-field-...
0
votes
1answer
39 views

drupalSettings value is undefined [duplicate]

I am trying to call a JavaScript function when I click on a button in a form. I have multiple buttons in a for loop and I have attached the library to all those buttons. (Not sure whether this is a ...
0
votes
0answers
11 views

Radiobuttons on a custom entity form do not get set once ajax is bound to the radio button

I am trying to trigger a change of a select box options on the change of a set of radio buttons in an entity form. The only event I am able to get the ajax event to run is the click event as I am not ...
0
votes
1answer
24 views

Conditional fields on content type with paragraphs [closed]

I saw this question repeat in a few places without an adequate answer. I have a D8 site that has a certain contain type ('deals') which contains an array of 'deal' paragraphs. Each 'deal' contains a ...
-2
votes
1answer
43 views

How to get all values of particular custom field of user entity using EnitityQuery?

I have added one custom field to user entity called as "customer_no". On User Registration Form, I want to check whether customer_no already exists. For that, now I want to Fetch all user's values ...
0
votes
0answers
44 views

Custom form throws 'Cannot unset string offsets' error

I'm trying to build a form for my custom entity and so far the form is looking pretty good. However, when I press the Save button I get this error: The website encountered an unexpected error. Please ...
0
votes
1answer
25 views

Ajax callback is not working on views exposed filters

I am implementing dependent filters in views exposed filter for content:datasource search(Solr search). I have a requirement that in exposed dropdown field when a category is selected, by ajax i need ...
0
votes
0answers
26 views

Hook or event when Media file is inserted/updated/deleted but only when node form submitted

I created a field of type "Entity reference" and referencing an item of type Media. In other words its an image field. I would like to execute code with an hook or an event when an image is added, ...
0
votes
1answer
32 views

Make a password security check for the register form

I have a register form that is output in a controller using the following code. $form = $this->getUserProfileForm(); return [ '#theme' => 'maubl_user_inscription', '#form' =&...
0
votes
0answers
13 views

Getting multiple inputs with custom field

I created field for timeline and I selected unlimited for " Allowed number of values " and I "placed" this field to my custom type, After saving content I`m getting multiple instances of this field ...
0
votes
1answer
13 views

How to add class to the options for type radio present under radios?

function template_preprocess_bef_radios(&$variables) { $variables['children'] = Element::children($variables['element']); _bef_preprocess_nested_elements($variables); foreach($variables['...
1
vote
4answers
61 views

How can I use the core link field widget with title and URL in a custom form?

I want to add a link field to my custom form. Below is the code that I have been trying to use but no success. So can anyone let me know how to use core link field in a custom form in Drupal8? The ...
0
votes
1answer
21 views

How do I make a form field go back invisble after I uncheck a radio button?

I'm currently building a form where the goal is that the administrator will have to choose between 3 radio buttons. If one click on any of the radios, a specific field shows up (There are 3 fields set ...
0
votes
1answer
21 views

Entity Validator failing Integer for not being integer

I have a custom entity with an integer field with the following baseFieldDefinition: $fields['permission_level'] = BaseFieldDefinition::create('integer') ->setLabel(t("Permission Level")) ...
0
votes
1answer
26 views

Altering UserPasswordForm redirect with a custom submit

I want to alter the redirect of UserPasswordForm from Drupal’s core, I did this function maubl_user_form_alter(&$form, FormStateInterface $form_state, $form_id){ switch($form_id) { case '...
0
votes
0answers
30 views

Ajax call in form alter of inline entity form

Inline entity form is using in bricks. In that Inline entity form, there is 2 dropdown fields available . i want to form alter in that Inline entity form, so that selection of one dropdown value, ...
0
votes
0answers
16 views

Lost name attribute after recharge select field with ajax callback [duplicate]

I have a great trouble with ajax callback, I need to recharge a select field, the callback goes right, but, the returned field in ajax request goes without name attribute, so, I lost it while submit ...
0
votes
0answers
17 views

user_login_submit doesn't work when called in an inner function

We have a shared register function that multiple pieces of our app use. When registration is successful, we log the user in. But for some reason, when a user completes this project via browser in the ...
0
votes
0answers
35 views

How do I programmatically add fields to Paragraph types?

I have one paragraph type of Product. and I have to add one field to paragraph product programmatically, how can I achive this. function my_module_field_widget_paragraphs_form_alter(&$element, ...