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.

1
vote
1answer
221 views

How to clear form element values after validation error

I have a rather complex form validation depending on multiple fields. If validation fails, I would like to set the form values (of all or some explicit fields) to an empty value. This is what I tried, ...
1
vote
1answer
31 views

I am not able to override the form #access setting [closed]

I cerated a form alter with the file entity media upload browser. I studied this answer of how to alter this form. I then debugged and found that for what I wanted to do, I am in step 4 of the file ...
0
votes
2answers
177 views

“managed_file” form field type returns null value in my form submission

I am have been struggling with this for the past day or so. I am simply trying to create a custom entity and populate/or update the image field with the fid. Whats weird is that every other form field ...
0
votes
1answer
40 views

Adding alt text to a form field

I know that alt text is usually used for images, to help screen readers etc. In this case my task manager wants me to add 'alternative text' to calendar items, to better satisfy 508 requirements. This ...
4
votes
3answers
298 views

Change value on validate form when I create or edit a block

I need change a value to element on form validation. I have this code: /** * Implements hook_form_FORM_alter(). */ function MY_MODULE_form_alter(&$form, FormStateInterface $form_state, $...
-1
votes
2answers
191 views

How can I use media fied in a custom form in Drupal 8?

I tried something below, which is not working in drupal 8. $form['upload_documents'] = array( '#type' => 'media', '#tree' => TRUE, '#title' => t('Upload your documents'), '#...
0
votes
1answer
59 views

How to use profile2 profile type in custom form?

I'm building a multi step sign up form for my drupal 7 website, so I want to use one of profile type from profile2 in first step. For such purpose I'm using this code: function personal_info_form($...
0
votes
0answers
43 views

Disable specific select field option

I'd like to disable an option on a select field (based on a user role). I am doing this inside a form_alter hook. I got the user role condition working fine but I can't seem to disable a select option....
6
votes
1answer
543 views

How to add taxonomy term reference field in a custom form

In the previous version of Drupal, it was possible to reference taxonomy tags in Drupal's forms using the following option: '#autocomplete_path' => 'taxonomy/autocomplete/'.$vid, However, in the ...
0
votes
2answers
25 views

“Login to your account” form block not showing on frontpage when “View published content” is disabled for anonymous

I am new to Drupal 8 but not to Drupal ; In Drupal 8, I enabled the "Login to your account" block in one of my regions : But on the homepage, the block is not showing in the correct region, instead ...
0
votes
1answer
235 views

How to save a checkbox config_object in the schema files?

We have a custom module with the following files. It is mainly used to store a list of content types that this configuration applies to. When saving the configuration, we get the following code. How ...
0
votes
0answers
333 views

Form ajax submit handler not called when loading in ModalDialog from submit handler of another form - Drupal 8

I've custom form (suppose FORM1) with few fields and AJAX submit button. When user submit this form, I'm opening another form (suppose AJAXFORM1) in ModalDialog with few more fields and AJAX submit ...
0
votes
1answer
77 views

Custom form to modify only some fields of an EntityForm

I generated an Entity following this guide. Now I would like to create a custom form to modify only some fields inside a single entity. I was thinking to create an action inside the controller calling ...
0
votes
0answers
12 views

How to add an error message after checking the form in the right place?

There is a form component on which I added a function <?php $form['submitted']['tel']['#element_validate'][] = '_custorm_validation_form_validate'; ?> in the function itself wrote the ...
0
votes
1answer
108 views

How to avoid “The form has become outdated” after login in separate tab

I've read this and this and I can't see how to apply that to my situation, so asking another question. not-logged in user visits a page with a form on it. User opens a new tab and logs in. User ...
0
votes
1answer
436 views

Different node form id for add/edit

I recently found that unlike Drupal 7, D8 has a different form id for addition and edit of nodes. Is there a specific reason for that? Because this makes the hook_form_FORM_ID_alter() less granular as ...
0
votes
1answer
20 views

Table doesn't render on ajax command

I have a function that returns a render array for a table; private function _files_table($job_id){ $files = $this->_query(" select * from JC_Documents_Recent_Revisions ...
0
votes
1answer
127 views

Cannot use object of type stdClass as array error in node save

I built a custom form and one of them is of type geocode with lat/lon fields. When I try to save the node I receive the following error: Cannot use object of type stdClass as array in /var/www/...
1
vote
1answer
47 views

Parameter upcasting in Forms: buildForm works, submitForm doesn't

Route: mymodule.applications.payment_form: path: '/payment/{submission}' defaults: _form: '\Drupal\mymodule\Form\PaymentForm' _title: 'Pay Fee' requirements: _role: 'applicant' ...
0
votes
0answers
13 views

drupal makes 2 requests on form submit

I have drupal 7 running on nginx server. If when i have from on page and press submit in chrome dev tools I see two requests. One has 302 response, and second is 200. If you look at the pic. Is that ...
0
votes
1answer
134 views

Register form breaks after changing submit button value with jQuery

I need to change the submit button value (text) based on the selection made in a certain register form field. I accomplished this by using jQuery: (function ($) { $(function() { $("#edit-field-...
0
votes
2answers
27 views

Can an AJAX form request replace elements of different types?

I'm trying to write an AJAX form in Drupal 8. I managed to get a simple example working yesterday, but today, my work fails without error. I was wondering whether anyone here could spot my error. ...
0
votes
0answers
58 views

session value not updating in theme variable for anonymous user

I am working on multi-level forms, and storing form values in session to display result on final page with some form values. but its works fine only for authenticates users. For anonymous users ...
0
votes
0answers
14 views

What does the '#localized_options' in certain form elements do?

I am unable to find relevant documentation (something like Form API reference) on what the '#localized_options' optio do. I've seen some code snippets where it is used to add attributes like 'id' but ...
0
votes
1answer
229 views

Custom autocomplete form and autosubmit

I've added an autocomplete function for my views_exposed_form (a text input) using this tutorial and it works (https://www.linkedin.com/pulse/implementing-autocomplete-drupal-8-custom-callbacks-...
1
vote
0answers
224 views

Google invisible recaptcha doesn't work with form file fields

I have a form in my drupal project which has a managed_file field. It worked perfectly until I added invisible recaptcha for the forms. The file is getting uploaded but when I submit the form the ...
0
votes
2answers
63 views

How can I get the uploaded file path of a contact form in drupal 8

I'm using the hook_mail_alter() to create a custom email for contact forms. I was able to get the fields labels and values and use a twig template to send the email. Most of it is working just fine, ...
0
votes
1answer
182 views

Create a Custom Ajax in form alter

Hi i have a problem to create a custom ajax, i have the following code. the problem is i cannot make the code working no response nothing working for ajax callback, is simple but i try to put i src ...
0
votes
1answer
57 views

Error Passing Extra Parameter to Custom Form

I have a simple custom form that works until I try to add a custom parameter for my module called "forms_admin". These are the contents of my forms_admin.routing.yml forms_admin.settings: path: '...
0
votes
0answers
11 views

How to use and validate profile2 profiles in custom forms?

this is Abdullah here, I'm stuck with a problem and hoping a working solution from you. I am trying to built a multi step sign up form for my drupal 7 site, therefore I followed this article: http://...
0
votes
1answer
161 views

Set the message field as not required in a custom contact form

I have tried many things to set the message field as not required. 1-The more obvious in form_alter $form['message']['widget'][0]['value']['#required']=false; $form['message']['widget'][0]['#...
0
votes
1answer
28 views

FAPI text_format field value not being passed to submit handler

I created a form that I wanted to be reusable. So I created to form below to imported into a add form and a edit form. Please be aware I do have the validateForm, and submitForm function in my code. ...
0
votes
1answer
172 views

How can I get the Contact Form “Manage Display” Settings programmatically?

I am trying to use hook_mail_alter to create a custom contact mail. I want to get the display setting of the contact form. (example path: http://mysite/admin/structure/contact/manage/my_contact_form/...
0
votes
1answer
177 views

How to get parent node values on inline entity form hook alter?

I am using inline entity forms to create a paragraph in a node form. When I add a node I want the title of the node form to be copied to the paragraph when I click on "Add paragraph". I use ...
0
votes
0answers
363 views

Capturing the event of “add another field value” and current form state

I built a content type (journey plan) to allow users to choose steps in a cross-countries journey. The users choose a country from a menu (field_country), and put one or more cities from that country ...
0
votes
0answers
82 views

Different registration pages with different fields for different user roles

I want to make different registration pages with different fields for the roles. I've used Profile and created different profiles types with different fields for each one and included it in the ...
0
votes
0answers
21 views

Permission for Add more/Delete button for entity reference field

In my Drupal 7 Project, I want to know how can I define permissions for Add more/delete buttons and submission form for specific rules? For example users with role A are not able to see add more/...
0
votes
1answer
37 views

How to let editors place custom forms?

I have a custom form: \Drupal\module\Form\CustomForm I want to be able to embed this form in a basic page by adding a shortcode/variable to the basic page such as: [form][/form] or form This is ...
0
votes
0answers
50 views

Ajax to update select list, an illegal choice has been detected

I am updating a select list via Ajax - the list is an entity reference field with cardinality of 4. There is a plethora of "An illegal choice has been detected" results; however, none of them work ...
0
votes
1answer
59 views

Views filter handler for user authored from Custom Form

How can I make a custom views filter handler to filter a list of users which the current user created? For example: The user adds members to the site a view will show only the members that the user ...
0
votes
1answer
38 views

#States required not working

I'm trying to use "#states". When my checkbox is true, I want to make "required" another field. Drupal prints the "required" asterisk but not correctly. Here it's the code: // Return origin. $...
0
votes
1answer
141 views

How to use ajax in field widget form?

I need to store a country and a region for geographical objects. Countries and regions are stored in a taxonomy vocabulary. Moreover, some countries have regions (as child terms) but someones don't ...
0
votes
0answers
82 views

Toggle button status (enabled / disabled) using ajax drupal form

How to implement two buttons that alternate according to the active button, for example: Through personalized module I want to show the user the option to mark between two answers, I am using two ...
0
votes
2answers
337 views

Messed-up div IDs for ajax-modified form field

I want to change, using Ajax, some attributes to field2 (a select widget) when field1 changes: In mymodule.module: function mymodule_form_NODETYPE_FORM_alter(&$form, &$form_state, $form_id) {...
0
votes
0answers
12 views

Number resets to 0 on ajax callback when there's an initial number set - AJAX Graceful Degradation

Been scratching my head for over 2 days and I can't figure it out why each time I click on "add more" button, the initial count being reset to 0. I've get the code from Example: AJAX Graceful ...
0
votes
0answers
26 views

Submit handler issue

I am completely new to Drupal, I have just started today to be honest. I am trying to create a simple form that would show a message after the submit button is clicked. The issue is that when I click ...
0
votes
0answers
14 views

Why does this entity form when saved create a new instance rather than save the present one

This may be a question which only the most familiar with the module EntityForm can help with. My situation is this. I have a content type called project and each node has an entity form attached to ...
0
votes
0answers
39 views

hook_node_access() is not called with anonymous users

I have created a content type that only authenticated users with specific roles are permitted to view or edit, but in some cases I want to give permission to anonymous users to see specific nodes. ...
-1
votes
1answer
41 views

How to render a form with 2 fields for each line?

I'm looking for a way to render a form with 2 text-fields in to the same (for each) line. I would like to do this using hook functions, so I tried with this: function mymodule_form_alter(&$form, &...
0
votes
0answers
26 views

Callbacks as objects

I find that in Drupal 8 we can specify the submit/validate callbacks as objects. So I was wondering, if we are form-altering a certain form, how do we specify the submit callback as an object? Like ...