Stack Exchange Network

Stack Exchange network consists of 174 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
2answers
351 views

Submit form load results instead of messages

I am testing out the new Drupal 8 custom modules and currently stuck with the submit form handler to load form submitted results in the same page and my current functions of last submit is this (...
0
votes
1answer
536 views

Computed value on multipage Webform

I have multipage webform. I want to compute the value of the component (Hidden -type) which is on the second page based on the data submitted on the first page. I'm using hook_form_alter and added my ...
0
votes
1answer
18 views

Form alter overriding submitted values

I have a form_form_id_alter function that sets some default values and a checkbox checked. If I submit the form, with the checkbox unset and it fails validation, the re-rendered form re-sets the ...
0
votes
1answer
544 views

Custom wrapper field

I have a normal field submit: $form['submit'] = [ '#type' => 'submit', '#value' => 'Submit, ]; But I wish he had a complex wrapper without using #prefix and #suffix. This wrapper also has ...
0
votes
1answer
557 views

Embed a form inside a modal

I have a modal in my form. $form['myid_print_preview_modal'] = array( '#type' => 'item', '#markup' => '<div id="myid_print_preview_modal" title="ID Preview"&...
4
votes
3answers
2k views

How do I change the default value of a field with AJAX?

Related to my previous question: Form fields created via Ajax are missing element attributes I have a date field and a series of text and number fields which need their default values to change based ...
3
votes
6answers
6k views

How to hide default “N/A” option for checkboxes?

I have a "gender" (checkbox) option that I want to show on the user profile page (but not on the registration page). The options are "Male" (default) and "Female". Since I don't make the field ...
2
votes
2answers
39 views

Automatic username generation from name fields at registration

Drupal core 8.6.5 I am trying to change the user registration process to omit the username field and generate the username from the first name and last name. Since I am new to Drupal and want to ...
0
votes
1answer
619 views

How to get error messages to display on the form, rather than after the page is refreshed?

I have a form that has radio buttons and the user needs to select at least one option. If they do, a modal window will pop-up. If they don't, I need to redisplay the form with the saved values and the ...
5
votes
3answers
82 views

Require field on publish only

I have a D8 site on which I would like to require an image field to be completed only when a node is published; if the publish box is not checked, the field should not be required. I was able to do ...
2
votes
2answers
3k views

how to get all the values in an edit form

I want to see all the values in my edit form, I tried dsm($form_state->getValues()) but i dont get anything. if I do dsm($form_state) I get a huge amoung of things too much to look through. ...
0
votes
1answer
28 views

Webform Submission Using Rest API POST method

I just created the webform and added fields. I need to create a Webform Submission Using Rest API POST method. I just installed Rest & Rest UI modules for this. But when I try to test my API ...
0
votes
1answer
563 views

Load Javascript when a particular form is loaded

I have the code below in my own drupal module(myid): myid.module file: function myid_init() { drupal_add_js(drupal_get_path("module", "myid") . "/js/myid.js"); } function myid_menu() { $...
0
votes
1answer
589 views

AJAX Calculator

I'd like to have three separate but interconnected calculators that generate their output with AJAX (i.e., no page refresh). Would this process work or is there perhaps a simpler/more trodden pathway ...
0
votes
0answers
8 views

How to clear the publish checkbox in form or form element validation

I have a D8 form where when a test involving the value of other fields fails, if the publish (field = status) checkbox has been checked the validation should fail and the checkbox should be cleared ...
0
votes
2answers
588 views

Creating a custom login system by developing a new module

I've created 2 files: login_process.info login_process.module I've created the table "user" in the database that Drupal is using. I want to display a custom login form with fields "Username" and "...
-4
votes
1answer
31 views

Find different node in hook_node_form_alter [closed]

In the function hook_node_form_alter(), i still want to get an other node, because i want to set a field value programmatically in dependencies on the value of an other node (the parent node). But i ...
1
vote
1answer
26 views

Does Entity Autocomplete has database leak?

Lately in one of our prod database the "key_value" table became 2.4GB large. When I took a closer look I could see that there is around 200 000 records in it, and 90% of them are entity_autocomplete ...
0
votes
1answer
577 views

Redirect to Continue Multi Step Form

I am building a form that can either begin on the home page or at the '/apply' url. I used this tutorial to build the multi-step form. The form works great if I start from '/apply' and begin at the ...
-2
votes
0answers
27 views

How can I build a Presentation Manager? [on hold]

My project's structure: I'm building a Presentation Manager. A Presentation has a title, an image and Slides A Slide has a type (can either be text, image or video) We want to be able to re-order ...
0
votes
1answer
81 views

How to identify and target a form element?

A similar question has been asked before: How do you identify a form element? I am using the Devel module and dpm($form) outputs the object nicely: But I can't set/change the default value of a ...
0
votes
1answer
614 views

How to add AJAX call back from another AJAX result in a form

I want to use 2 AJAX call back within a form. The scenario is like I am having a text field and a Search button which is defined in the form alter function. After entering a text and clicking on the ...
1
vote
0answers
35 views

How can I add a property definition to an existing field?

I have a file reference field FileItem that has a display and description property but I want to add an extra one. I was hoping I could just override the default widget but I can't use this to store ...
0
votes
0answers
31 views

Form action as controller method?

I'm trying to fix a form that was created using a twig template. The form was not working because there was no action, nor was the form created using FormStateInterface. It's just a block that is ...
1
vote
1answer
23 views

Add another button removes the default values from my fields on node form

I have a node form on which two fields are displaying. One is a list of radio buttons which is required field. I am getting a value from url using arg(3) and setting the default value of that field $...
0
votes
1answer
384 views

Pager not working when $form['table'] is called with AJAX

For a statistics page I let users select the right file in a select list. After that I generate a table with stats. This table also has a pager (that worked without the ajax part). Now I did ...
0
votes
2answers
750 views

Ajax error on node form edit page

I'm trying to ajaxify part of node form. I have a hook_form_alter that adds extra ajax property to a widget of select field. The problem I'm facing is the callback method / function, which is not ...
0
votes
2answers
600 views

Views VBO: Set custom action with custom attributes selected in form

I have a view of persons. I like to add the persons to an event. I also like to set the status of the resulting relation to one of the values "optional" or "required". Therefore I use VBO on a list ...
0
votes
1answer
29 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 ...
0
votes
2answers
628 views

How do I theme the contact form?

I am trying to create a contact form for users with username, email, message, and submission button, but I want to customize the structure of the form. Where do I get the structure of the form to ...
19
votes
10answers
29k views

How do I add a custom validation to an existing form/field?

It's all in the title: how to add a custom validation to an existing form (or form field) in Drupal 8? I have a form that I haven't created that I want to alter to execute my own validation rules on ...
0
votes
1answer
631 views

How to stop a form refreshing after callback

I have a form, which is made up of a listbox and a textarea, the listbox holds a number of items that related to records in the database. The user can select an item from the listbox and select the ...
1
vote
2answers
43 views

Form input returns “1” instead of real value

On this page I have an select list with values from a file directory. This works. Only after submitting it doesn't get the value of it. It makes it "1". Normally with a "normal" select list this ...
-2
votes
0answers
41 views

How to create depended fields in drupal custom module [duplicate]

I know this has been asked before and I'm trying to use the example at Dynamic select list in the form (dependent dropdown) but I am struggling to get the desired results. I Have a form that presents ...
-2
votes
0answers
20 views

onchange autosubmit autocomplete not working for safari

I created a custom autocomplete form in Drupal 7. Its working fine for chrome and firefox. but it's not working for safari and Mac. My code: function fitnessHomeSearch_form($form, &$form_state) { ...
0
votes
1answer
618 views

How can I dynamically disable a single required field from validation in a form?

This is an extension of this question: Need help with AJAX callback function for text field validation in form_alter I have a form with a Username autocomplete field (txn_user). The editors want to ...
1
vote
1answer
604 views

Redirect to Different URl on validation errors in form builder

I am using drupal 8 fapi and i have user case as below I have a form on https://example.com/landing-page and I submit the form and there are validation errors .the page should reload as https://...
0
votes
1answer
49 views

$form table displays no table data

I just made a $form['table']. It shows enough rows (the count of the total rows in database) only it doesn't show the results. I tried using #value, #title, #markup but nothing works Screenshot of ...
0
votes
2answers
583 views

Add class to all labels in a comment form

Pretty straight forward. For every label within a comment form, I wish to add a particular class to it. Using only functions in template.php, in Drupal 7, how can this be done? If it can't be done ...
0
votes
1answer
653 views

Inline Entity Form validation

Created a content type and add taxonomy form in it using Inline entity Form module. So, the rendered taxonomy add term looks like : What I want to do is ADD CUSTOM VALIDATION to the "NAME" field. I ...
0
votes
1answer
637 views

How do I throw values calculated back to buildForm()?

I am trying to throw back values that are calculated in submitForm() to buildForm(). How do I add more state values into it? /**  * @file  * Contains \Drupal\resume\Form\ResumeForm.  ...
0
votes
0answers
23 views

Contact form throws “an illegal choice has been detected” error

I try to add a contact form with add contact form from the contact module on Drupal 8 but I have this error when I try to save the configuration: The recipient field is required An illegal choice has ...
1
vote
1answer
17 views

Programmatically disable content translation options in content edit form

I want to programmatically disable the content translation options located at the bottom of the content edit form (see yellow area in screenshot): I know that i can disable the revision information ...
4
votes
1answer
618 views

Prevent dual submit on form submission

I've got a form that submits via AJAX and in the callback I need to rebuild certain parts of the page to reflect the newly submitted data. One of these parts is the form, which I need to clear all ...
2
votes
1answer
600 views

How do I change the ID of a copy of an exposed filter?

I'm using answers from Expose a view's filters both in a block, and in the actual view to duplicate an exposed filter as a block and make it appear in another region on every page. I want to ...
1
vote
0answers
39 views

Validate a field only if the value has changed and/or if it is a new value

I'm building a module that get information from the NCBI database API -- specifically it get's publications, from my group, by using a publication ID. I want anyone in the group to be able to add a ...
0
votes
0answers
12 views

Upload file using File type=“managed_file” disappears immediately when clicked on upload?

I want implement upload zip file using FORM API where I want to show the progress bar for uploading file so I have written code like: $step2['browse']=array( '#type'=>'managed_file', ...
0
votes
0answers
29 views

Embed user edit form in a block

I am trying to embed current user edit form in block. Actually I want just to embed some of the newly added fields. I tried to follow this code: Embed some user profile fields in a block form But I ...
4
votes
3answers
3k views

Node add form alter & submit custom field

I have a content type "event" with a field called "field_pricelist". It's a dropdown with no values, I add the values when I alter the form. The values come from a custom table (install / schema) in ...
1
vote
1answer
785 views

Programmatically load and submit the user form

I want to programmatically load the user profile form for a particular user and re-submit it without changing any of the existing values. The reasons are complex but I am dependent on gathering data ...