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
1 answer
59 views

Why a form doesn't keep the value created during construction

Here is a form using DI for $this->entity_type_manager There is also a radio-button with Ajax (I have added the code as it is maybe the reason of my problem) class myForm extends FormBase { ...
Baud's user avatar
  • 570
0 votes
0 answers
405 views

How to add checkbox using hook_field_widget_WIDGET_TYPE_form_alter()

Running Drupal 9 with paragraphs module, paragraphs collapsible and paragraphs jquery ui accordion installed. I wish to modify paragraphs' form, specifically where it displays private files by adding ...
SomebodySysop's user avatar
1 vote
1 answer
559 views

How can I set a default value to show for a taxonomy term name in its edit form?

I have a site where I have a taxonomy term. I want to set a default value to the term name and display it when the form loads. In hook_form_alter(), I tried to set the default value to Check term name ...
Raja Chakraborty's user avatar
1 vote
1 answer
409 views

Get the node title field value in the form_state

Drupal version 9.3.9. This is a process of Ajax callback, where the value of the title field is required. In the form node add, the title is displayed. It seems that the form_state does not apply to ...
Belba's user avatar
  • 71
1 vote
2 answers
563 views

How can I change the title of the node/add page of a specific content type?

I want to change the title of the node/add page of a specific content type. Twig debug only shows me file names that would also change the titles of other content types. There was a module for this in ...
0711master's user avatar
0 votes
0 answers
87 views

Creating link option in form and modifying it's url in form alter hook

I'm searching to modify a node add form, so far i added a personal field "link" to display as a button to add another node type if the user wants to, that link has this code in ...
Ernesto Alfredo's user avatar
0 votes
0 answers
77 views

How can I standardize the query from exposed form input?

I apologize in advance if the title for this post is misleading, my intention is to use exposed form input from a form in a block display (not on the view page) to build a query on a page display for ...
Steve's user avatar
  • 351
-2 votes
1 answer
40 views

How to implement a social media feed [closed]

I am creating a social media app and basically need a page that is a form with fields for the users to fill out and add a new post to their feed (form connects to the feed). More detail: The form ...
Help appreciated's user avatar
0 votes
1 answer
111 views

How to add a boolen attribute to a form?

I am trying to add the boolean attribute "novalidate" to all my forms. I have tried numerous approaches in my theme_preprocess_form function but no luck. I see in some preprocess functions, $...
liquidcms's user avatar
  • 1,224
0 votes
1 answer
99 views

Render Submitted Fields of a Form to Email with Title + Value

I have a quite complex form based on \Drupal\Core\Form\FormBase with many (partially nested) fields and want to send the full contents in an email on submit. Currently I have public function ...
Alex's user avatar
  • 87
-2 votes
1 answer
803 views

How to check and disable one of the checkboxes in a form?

I found this snippet in the code for a form ($roles is an array of roles). $form['config_options']['roles'] = [ '#type' => 'checkboxes', '#options' => $roles, ]; // Check and disable the '...
Free Radical's user avatar
  • 15.1k
-2 votes
1 answer
20 views

How can I loop on checkboxes to hide all using mlid: from the datatable?

function ts_core_form_menu_overview_form_alter (&$form, &$form_state, $form_id) { $form['mlid:11242']['hidden']['#type'] = 'hidden'; $form['mlid:11246']['hidden']['#type'] = 'hidden'; $...
Euclid.H's user avatar
0 votes
0 answers
17 views

Is there a way to improve the entity autoselect especially for multiple entities?

The entity autoselect is a strange UI element that lets you type something, if you select a match, it puts that text in. If you want to include two items you need , to separate them. What if there ...
artfulrobot's user avatar
  • 3,989
0 votes
0 answers
47 views

How to clear selected values from multiple select field

I have a form with a multiple select field where a user can select several values in it $form['export_type_section']['export_type'] = array( '#title' => t('Export types'), '#type' => '...
angela83's user avatar
0 votes
1 answer
46 views

FormAPI - Values of AJAX added fields missing from values array on submission

I'm using the Form API to create a form where I have multiple instances of a fieldset. Each fieldset contains the same fields, one for storing an email address and another for another bit of ...
AlbionBrown's user avatar
2 votes
1 answer
550 views

How would I disallow special characters in usernames?

By default, Drupal 9 allows usernames to have spaces, periods(.), hyphens(-), apostrophes('), underscores(_) and @ symbols. How would I disallow spaces, periods, apostrophes and @ symbols?
cofihouse's user avatar
0 votes
2 answers
153 views

How can I alter the login form in the login block but not in the login page?

How should I use hook_form_alter() to modify the user login block but not the user login form page? Everything I've tried either modifies both entities or doesn't work, not even using the following ...
cofihouse's user avatar
0 votes
0 answers
27 views

If i have to add a content in drupal through custom form which table in database should be used? [duplicate]

I have created a custom Form through form api which only contains one form field of adding image to node and their will be a different form through which i am going to add body , title and tags in ...
Vighnesh Sadagopal's user avatar
0 votes
1 answer
41 views

How can I access or expose the Commerce data in $order->data[] to the Rules module?

Following this old checkout_pane_example.module tutorial, I created a custom Drupal 7 Commerce checkout pane. It's simply a text field to collect special order instructions from the customer. ...
blue928's user avatar
  • 3,804
0 votes
1 answer
138 views

Link to images in form view creates wrong url

I noticed this after drupal 9 update, but I've tried to find the exact moment when it was broken and I couldn't find it. I use S3 and cloudfront for images so maybe the problem is related with that ...
zapico's user avatar
  • 83
0 votes
1 answer
48 views

Templating the user edit page

i'm using the theme startupgrowth lite and i want to theme my user edit page , only when the user is a 'testeur' and he's editing the 'candidate user profile'. i know that when i want to modify the ...
Amine's user avatar
  • 1
1 vote
0 answers
92 views

How to reload flagging form via ajax?

My task is to ajaxify complex flag form (with additional fields). I need this because the default ajax flag does not dupport fiedls. I need to have the flagging form for create flag and then update it ...
Sergey Kravchenko's user avatar
-1 votes
2 answers
554 views

How do I sanitize the uploaded files name for sending safely as email attachments?

I have create a form that upload a file. This file is send as email attachment .. $form['cv'] = [ '#type' => 'managed_file', '#title' => 'Votre CV', '#...
Matoeil's user avatar
  • 3,355
0 votes
1 answer
126 views

After rendering entity form how can be modified?

I rendering a custom entity form display with the following code: $form = $this->entityFormBuilder->getForm($entity, 'array_delimiter'); This is perfect, as it shows what I set on the form ...
golddragon007's user avatar
2 votes
2 answers
2k views

Form with two submission buttons

I try to create a form with two submit buttons and each button will use a different function: the default submitForm function and a custom submitFormEndSession function. So I have this code: class ...
Auraylien's user avatar
0 votes
1 answer
1k views

InvalidArgumentException: Class ... does not exist in custom configuration form [closed]

I create configuration form, so that I could dynamically set the API key for my custom weather module. But when I write in the url address http://drupalsite/admin/config/services/weather/settings I ...
bimsalrobit's user avatar
0 votes
0 answers
480 views

Batch Error: Using $this when not in object context, so Can I call batch method in non static way?

The existing code when a form is submitted I execute this batch : /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $node_titles = ['node1', '...
Marwen Amri's user avatar
0 votes
1 answer
59 views

specific submit handler to user form

I have a submit handler to the user form. It redirect the user to a specific page. use Symfony\Component\HttpFoundation\RedirectResponse as RedirectResponse; /** * @file * Primary module hooks for ...
Frédéric Hébert's user avatar
1 vote
2 answers
554 views

Confirmation message on comment submission

When a comment is submitted, no confirmation message is shown and I would like to achieve this. I want to show the following message. Your comment has been added for review and approval. I tried ...
chaydru's user avatar
  • 43
1 vote
0 answers
128 views

Can't save value of custom datetime field

I'm reaching out because I just can't find out why my custom datetime field isn't saving its value after I submit. Context: I've created a field containing two datetime fields. I will use it to add or ...
Dancoo's user avatar
  • 11
0 votes
1 answer
56 views

Time spent with custom module

Can anyone help me with this, I want to activate time spent module on my custom form module, and store the time spent on a field on my form. I think that I could do it on the file timespent.module ...
Amine's user avatar
  • 1
3 votes
1 answer
60 views

How to not split select list by content type

This is about the regular select widget that you can choose in the Manage form display page. If this widget is linked to an entity_reference field allowing several bundles to be selected; then you end ...
Baud's user avatar
  • 570
2 votes
1 answer
54 views

How to alter the view behind a select widget in a regular node edit form

I have an entity_reference field in a content type: field_node_ref In the field definition, it can reference all the nodes of a given type. The widget used for this field is a select widget Depending ...
Baud's user avatar
  • 570
0 votes
1 answer
85 views

Add default value to existing field

I have tried to add default value to an existing field using hook_form_alter() but it does not work. Below is the html of the fields <fieldset class="js-form-item js-form-type-textfield form-...
user avatar
1 vote
1 answer
445 views

Adding an "Accept Terms" checkbox on User Registration form

I need to add an "Accept terms and conditions" checkbox onto a user registration form. What is the best way to do this? Also, it seems odd to me that there is no easy way to use radio ...
Stephen Ash's user avatar
0 votes
0 answers
61 views

Altering user_admin_account and user_register_form

I'm pretty new to Drupal and I'm trying to build a Drupal 7 custom module to alter the user listings table in admin/people. I would like to display the first and last names of the users. I've already ...
cristina's user avatar
0 votes
1 answer
186 views

Validation for radio inputs don't work for me

I'm building a form with the drupal forms api. Validation works well for all my other fields. But I've started to try and work with radio buttons too now. It doesn't matter if I click on a radio ...
Jorn Reed's user avatar
-1 votes
1 answer
3k views

Formatting date field with the Form API

Hi there I'm using drupal 9.x and the forms api to generate a dynamic form. Altough I'm living in the Netherlands where the date format standard is 'dd/mm/yyyy'. I've looked around on the internet for ...
Jorn Reed's user avatar
2 votes
1 answer
282 views

Block Settings inside Form

Please I need help with my code. I have a form and a block created programmatically. The block embeds the form to show it on the frontend. The block also has some settings (form preffix text). I want ...
New To 'C''s user avatar
1 vote
1 answer
43 views

Place field in "Url Alias" advanced group section (path-0)

I'm trying to place my node field to the Advanced group - URL alias section. I'm doing it in custom hook_form_BASE_FORM_ID_alter(), where I'm trying to set custom #group like this: $form['my_filed']['#...
Bohus Ulrych's user avatar
0 votes
1 answer
634 views

Use ajax to save modal / dialog form instead of page reload

I'm looking for a way to save modal & dialog forms through ajax instead of redirecting the user after the form submit. Ajax is quite unknown territory to me. I've found several interesting topics ...
Apoc's user avatar
  • 92
0 votes
1 answer
32 views

How do I add a field to a node form?

The goal is to set a default counter, but let people override it. The counter should be the biggest value of the field plus 1. Using an event subscriber, FORM ALTER event. public static function ...
Interlated's user avatar
  • 1,405
0 votes
1 answer
70 views

Pager element not showing on form

I have a simple tableselect element inside my form and the tableselect rows are populated using a pager as follows: $pagerLimit = 10; //default value if nothing is passed in $query = $this->...
ilechcod's user avatar
  • 113
2 votes
1 answer
95 views

Why can't some fields be moved within details element?

I am trying to move 2 form fields to the advanced sidebar: dismissible and status. Status was already part of the meta container and setting #group='meta' on dismissable also placed it there; but ...
liquidcms's user avatar
  • 1,224
0 votes
1 answer
228 views

Custom validation constraints multi value paragraphs : how to get weight value

I am validating a multi value paragraph field using constraints. /** * Implements hook_entity_bundle_field_info_alter(). */ function cnfpt_internet_entity_bundle_field_info_alter(&$fields, \...
abelass's user avatar
  • 69
0 votes
1 answer
240 views

Custom constraints validation of multi value paragraphs: highlighting missing field

I am using constraint for the validation my multi value paragraph field. I can correctly implement the different validation rules but I haven't found out how to highlight only the erroneous field(s). ...
abelass's user avatar
  • 69
0 votes
1 answer
1k views

Build custom form with entity form field

I have a feature to migrate from Drupal 7 to Drupal 9. This allows me to build a custom form made up of static fields, which I define in the code of my module, and fields dynamically retrieved from an ...
Nathan Zim's user avatar
0 votes
1 answer
36 views

Using both Drupal Core Contact Form and contributed Webform module

I have a Drupal 8 site already utilizing core Contact Form. However, we now need a more complex form and thinking about installing a contributed module: Webform (https://www.drupal.org/project/webform)...
tkim49's user avatar
  • 1
0 votes
0 answers
263 views

Set ['#default_value'] of taxonomy term reference field via hook_form_alter()?

Here's a different question with the same taxonomy term reference field I mentioned in my previous question. Users with Administrator and Coach roles are granted permission to register Student users ...
hotwebmatter's user avatar
  • 2,102
-2 votes
1 answer
863 views

How to add anti csrf token to the forms (No Anti-CSRF tokens were found in a HTML submission form.)

When i was testing my drupal 9 website for security i got the error as "No Anti-CSRF tokens were found in a HTML submission form." solution is given as "use anti-CSRF packages such as ...
Nihal Kumbhalkar's user avatar

1
3 4
5
6 7
137