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
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Don't use it for entity or entity field forms.

-1
votes
1answer
13 views

Post form min max value

I have a custom form with min and max price value: $form['price']['min'] = [ '#type' => 'hidden', '#default_value' => isset($_GET['price']['min']) ? $_GET['price']['min'...
0
votes
0answers
15 views

Howto check if a form contains custom type field in hook_webform_submission_form_alter?

How to check if my custom element is added to form in hook_webform_submission_form_alter. Below is the screenshot what i am getting in form array. Custom composite element can be nested under 3 or 4 ...
0
votes
0answers
6 views

Getting problem in drupal form validation having ajax fields and other fields

In Drupal 8.5.6, I have a form with one ajax dependent dropdown field and two more other normal text fields. But when i give validation to form, when text field validation fails ajax fields gets reset....
0
votes
0answers
18 views

Why does the same form/field appear diffently depending on the browser? [on hold]

I have a custom content entity created with Drupal Console and the corresponding CRUD forms. In this entity there is a field defined this way: $fields['startdate'] = BaseFieldDefinition::create('...
2
votes
2answers
138 views

How to change the value of the publishing status checkbox to false by default?

I want that checkbox to be unchecked by default, because currently it's always checked. And I want this result: The structure of my content is as follows:
0
votes
0answers
17 views

How to make default user registration form to multi step?

I want the multi-step sign-up form for my drupal7 website. So I have 2 approaches are here. https://www.drupal.org/forum/support/module-development-and-code-questions/2010-12-15/altering-user-...
1
vote
1answer
10 views

How do I add reCaptcha to a form? [on hold]

I have a custom form on my site, and I want to attach a reCaptcha to it. I wasn't successful using the Drupal 7 code for this. Suggestions?
0
votes
3answers
34 views

Is the current form an entityform form?

I am using entityform module on some forms, but in a custom module, I need to check if the actual form is an entityform or not. Depending on the current form is actually generated by entityform, I ...
0
votes
0answers
21 views

How would i Add form fields dynamically via drupal ajax like the example below?

I've tried to use the addmore form from the examples form but im a little confused with adding the additional fields and having the fields appear in a row on the next line?? // Gather the number ...
0
votes
0answers
25 views

Passing field values to hook_mail_alter()

I'm new to Drupal so I'm sure this is a simple question for some. I looked around but I keep finding either D6 or D7 solutions. Nothing on 8. This is what I have in my form alter. if ($form_id == '...
0
votes
0answers
29 views

Textfield is not made visible when the radio form element is checked

In my form I have the following: $form['text_2'] = [ '#type' => 'textfield', '#title' => $this->t('Text'), '#default_value' => isset($config['text_2']) ? $config['text_2'] : ''...
1
vote
1answer
32 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
19 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
1answer
36 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
20 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
2answers
91 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, $...
0
votes
0answers
17 views

Custom ajax request in a form [closed]

I have a list with beacons which contain a location (latitude and longitude). These beacons can be added to a route and then can be given a name. To accomplish this, I created a custom form which ...
-1
votes
3answers
46 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
52 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
14 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
109 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
19 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
59 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
30 views

Contact form inside Content Type

Contact Form is not displaying on the content type page, as it shows empty page. I'm trying to follow the steps outlined in this article: https://www.flocondetoile.fr/blog/drupal-8-inject-contact-...
0
votes
0answers
59 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
62 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
69 views

How can I log validation error messages from custom forms extending form base?

I am using a custom form that extends formbase. I have required fields and fields with maxlength requirements. When submitting the form, the form 'automatically' checks for the required fields and ...
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 ...
-1
votes
1answer
24 views

how to render a contact form in a twig file [closed]

I am trying to render a contact form in a twig file with the hook "redbook_theme_suggestions_page_alter". I am new to Drupal 8. Any help will be appreciable.
0
votes
1answer
17 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
130 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
17 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
37 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
24 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
23 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
23 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
28 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
10 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
15 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
35 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
30 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
28 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
28 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
9 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://...
-4
votes
0answers
26 views

Alter Clientside validation error message [duplicate]

I have a content type job with client side validation enabled which is having public permission to add. How can I alter Clientside Validation error message? By default it is showing 'First name ...
0
votes
1answer
19 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
21 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
46 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
35 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 ...