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
4 views

Separate page (non-administrative) for adding content for Non-Admin User with few fields. Drupal 8

I have a Content type Product with fields Title Tags Picture (File) Status (Active, InActive) (For Administrator purpose) I want the other type of Users to add Product content without using ...
0
votes
1answer
575 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 ...
2
votes
1answer
637 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 ...
0
votes
0answers
8 views

#states property in field cause multiple values not work in form with paragraphs

Hi i have an issue with form How do i fix that? I have created custom Entity and few bundles in bundle i'm using reference fields one of them is from Paragraphs with multiple values. i needed ...
0
votes
1answer
13 views

Changing the html and order of system fields(pass/email/locale/etc) of user edit form

I have changed a number of forms accessible by users to fit a certain style. To do this I used an #after_build function that adds prefixes and suffixes to fields, as well as a bit of javascript. This ...
1
vote
1answer
26 views

How can I hide a field in the node add form but it unhide it on the node edit form?

I'm having a content type in that I want a field "Status" to be hidden in add content form page(I'm setting default value in that add content). Now I want that field to appear in edit form page of ...
0
votes
1answer
423 views

How do I add a date picker that is rendered from most the browsers?

I am migrating from Drupal 7 to Drupal 8. In forms I use '#type' => 'date_popup' for date fields, which Drupal 8 replaces by '#type' => 'date' and uses HTML 5. I'm finding it most ...
1
vote
1answer
814 views

how to validate minimum age in webform

I've got a question about webform and webform validation. I'm in D6.19 with webform 6.x-3.4 and webform validation 6.x-1.3 I'm adding a date field to capture age, and I need to validate that the age ...
2
votes
1answer
606 views

How to keep URL parameters on subsequent pages after a form is submitted?

I'm sending a referral form out to my email database and I've got it set up so that their email addresses get passed through and appended to the form URL like this: http://www.holbrooktravel.com/...
0
votes
0answers
19 views

How do I prevent NaN from appearing in the drupal form field?

For this field, if a user enters a space and leaves the field, the field fills with NaN, any idea how I can prevent that from happening? if (variable_get('variable', DEFAULT) === 1) { $basics_form['...
-1
votes
1answer
139 views

How can I redirect a form to the home page?

I have below code global $base_url; $form['submit'] = [ '#type' => 'submit', '#button_type' => 'primary', '#value' => $this->t('Submit'), '#attributes' =&...
0
votes
1answer
18 views

Is there a way to create hierarchical taxonomies checkboxes?

I have an issue where I want to keep sub category inside a parent category. Say, for preferred vehicle I want a checkbox like this in node creation form []Car []Volkswagen []Toyota []Bike []...
-1
votes
1answer
21 views

Error is not catching properly [closed]

I have a try... catch error handling while saving a custom form in the submit handler, but it is not going to the catch block nor throwing any error to the front end. Instead, it is throwing a fatal ...
1
vote
1answer
1k views

Show modal modal message on form success

I have a custom form that submits via AJAX. On form error, i simply return the whole form on my callback function, and the HTML is replaced, but i want it to open a modal dialog on success. What is ...
0
votes
1answer
476 views

How reset $form_state on ajax call for get real value in submit?

I have see some post about that,but i still have no real answer. In my form, user can select a register address in a select field. When he select an address, the ajax set value on some other fields : ...
0
votes
0answers
11 views

How can I set a Custom Field's label to 'visually_hidden' by default?

So I created my own field plugin, and I wonder if it's possible to set a default value for the display option. Obviously, there's no way to set this in the field formatter, and I don't see where I ...
4
votes
1answer
383 views

How to limit what is available for a role in Administration menu ?

I am using Drupal 7 and installed the Administration menu. It works fine and I am really happy with it but after creating a new role, and also creating a new user for that role, he seems to have the ...
0
votes
1answer
1k views

Captcha session reuse attack detected error message in form with anonymous user

I am experiencing a problem with the Captcha module 7.x-1.3 version (under Drupal 7.39) I don't use webforms My form is a simple Contact form My form does not contain any AJAX field My form does not ...
1
vote
1answer
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
29 views

Syntax to use form_alter with array in name attribute

I would like to modify some custom fields with form_alter in a contact form. I know for example how to change placeholder for this "name" field : Note : I removed all the unnecessary html elements ...
0
votes
1answer
590 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 ...
0
votes
1answer
31 views

How to save the webform data to custom table?

I designed a student registration form using webforms module. My requirement is to save data from the form to table student. How can i achieve this? Is there anyway to mention this in configuration ...
1
vote
1answer
724 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://...
1
vote
3answers
71 views

Set label of $entity programmatically in a custom form

I need to change the label of a custom content type programmatically. I've looked around but I couldn't find a solution. This is my custom form: class GroupContentForm extends ContentEntityForm { /...
4
votes
1answer
712 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
388 views

How to extend a specific node type form?

I am searching a way to overwrite the NodeForm to get a class per bundle. Actually EntityForm manages the form for all entities. NodeForm extends it and manages the forms for all nodes. I wrote a ...
0
votes
2answers
663 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 ...
0
votes
2answers
944 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
653 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 ...
5
votes
3answers
647 views

How can I block users from registering with disposable email addresses?

I have a site where users send messages to one another using the Private Message module, and they are notified of messages by email. On this site, there are a variety of spammers, scammers, and ...
0
votes
1answer
361 views

TinyMCE not appearing on custom form

I am creating a custom form and have run into a problem. I'm using the WYSIWYG module and for some reason the text areas on this custom form don't show as rich text editors (tinymce shows on other ...
0
votes
1answer
20 views

Hook form alter to check date field is empty or not

First of all I'm new to custom modules, I'm using hook_form_alter to do some custom validation, in the middle I have to check if a date field is empty or not, if empty I will display an error message. ...
0
votes
0answers
27 views

Disable validation when previous button is pressed

I have a multistep webform with required fields. The problem is that when I press the "previous"button in order to go to the page before the validation triggers and does not allow me to change the ...
0
votes
0answers
9 views

How to Create a Form with Ajax Output External to the Form?

What I want to achieve is: A form with a number of selects / textfields A div external to the form that contains information pertinent to the form's current input (i.e. not contained in the form ...
0
votes
1answer
778 views

Remove an uploaded file

I am working with files in a Drupal module. I added this form: $form['Background_image'] = [ '#type' => 'managed_file', '#title' => t('Image'), '#...
-2
votes
0answers
41 views

How to access individual form elements in theme?

I have overridden the default user login form in Drupal 8 using a different template in my sub theme, but it isn't of much use because when I access it in twig template, all I can do is <form {{...
1
vote
1answer
2k views

How to change Title field label and description for Custom Content Entity [closed]

I've created a custom content entity (generated via drupal console), I can add custom fields just fine via the cms. What I'm try to do now is change the default label from 'Name' to 'Artwork Title'. ...
0
votes
0answers
21 views

How to use FormBase with form_alter hook?

I am trying to edit the node creation form in order to add multiple 'tableselect' fields in it. My module adds options in a select field and add an ajax callback triggered by the 'change' event of ...
0
votes
1answer
804 views

How to add markup inside a form radio button div

Currently I have a form displaying radio buttons and I added some markup to it by attaching #suffix to the form element. However, I found that this didn't do exactly what I needed. This created the ...
3
votes
3answers
5k views

$form_state->setValue() doesn't save value

I have an validate code: public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); $form_state->setValue('my_variable', $...
2
votes
2answers
1k views

How to close the overlay after form submission

In order to be able to quickly edit Fullcalendar items, I altered the node edit form of the specific content type so the events are saved with AJAX and the page doesn't have to reload. However, I don'...
0
votes
2answers
633 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
2answers
592 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 ...
1
vote
1answer
819 views

How I can intercept an image field upload and validate it?

I have a content type with an image field. I need to validate this field because I need to check if user upload a real image or only a file with image's extension (like jpg, gif, png etc). I have ...
1
vote
1answer
5k views

Create a form programmatically and display result on template

I'm trying to create a simple page with a form. With the different filled fields I want to execute different EntityFieldQuery in the HOOK_form_submit. To finish I want to display the result of ...
0
votes
2answers
865 views

Loading a form from a form include file in a module

I have an external form that needs to be loaded inside a template file, used by a block. Right now, i'm a bit confused as to how to load this .inc. Looking at the API docs point to module_load_include(...
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 ...
0
votes
2answers
32 views

Rendering plain HTML in a form

I have HTML markup which is externally generated but I need to display in a form. I've got the following code in a form controller: public function buildForm(array $form, FormStateInterface $...
0
votes
0answers
16 views

When rendering a custom form, how do I use <button> instead of <input type=“submit”> for the button #type? [duplicate]

I have a render array for my custom form, which acts as a "Like" button for articles (but with custom functionality for our client). The button is defined like so: ... $form['like_btn'] = [ ...
1
vote
1answer
1k 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 ...