hook_form_alter() is the hook implemented by modules to alter the forms implemented by other modules.

learn more… | top users | synonyms

1
vote
1answer
28 views

How do I alter the login form?

I have used custom_module_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id); I get the form ID of other forms, but I don't get the login form $form_id inside the hook.
0
votes
0answers
32 views

how to get block body programaticaly [duplicate]

I have created custom block from Admin side like block/add , I want to display it content in hook_alter .module file.
0
votes
1answer
26 views

How to alter body of contact form?

When submitting a message in my site contact form in Drupal 8.x I have printed a message print_r($message['body'][1]);die; //in my modulename_mail_alter(&$message) I get the following ...
1
vote
0answers
17 views

Setting a #default_value to a select list during Feeds import

I need to set an entity reference select list's #default_value during (or after?) a Feeds import of Commerce products. Two term reference fields are used as arguments in the entity reference view that ...
-3
votes
0answers
12 views

How to get dynamic elements value in form api drupal

I have written code to display fields in dynamic text-field, but I cant able to get all values what I have entered function payroll_emp_form($form,&$form_submit) { for($i=1; $i<=2;$i++) ...
0
votes
2answers
23 views

How to use access callback for user role in drupal

How to use access callback for user role in drupal form API? For example User Role Administrator Authenticate User Anonymous user Teacher I want to view particular page for Teacher role users ...
1
vote
1answer
45 views

Saving and retrieving value in hook_node_form_alter()

This is in Drupal 7. I have managed to add a section to the node vertical tab. But I have not found out how to save the value and retrieve the value. After saving the node if i go back to the node ...
0
votes
0answers
11 views

How to add span tag in to webform element label? [duplicate]

I am trying to style my webform checkboxes and radio buttons differently. For this reason I want to insert span element in to the label and use it instead of original checkboxes. Found this module : ...
0
votes
0answers
18 views

Embed User Location in a block

I am trying to create a block that will allow the user to change their location on any page, not just on their user profile edit page. I am using the Location module, and assigning one location value ...
0
votes
1answer
38 views

How do I programmatically insert the entity ID?

I have added extra fields on the drupal 7 user registration form and created a module with a hook_form_alter function so that i can alter one field in the registration form. in the same file i also ...
1
vote
1answer
42 views

Drupal 7 hook_form_alter and submitting the form

I added some custom field so that i can get more information when someone registers into the website but i want to alter one field on the form. I created a module which has a hook_form_alter function ...
0
votes
0answers
16 views

Add new submit handler to Ubercart ajax “add to cart” form

I am using Ubercart ajax driven "adding products to cart" functionality and I'd like to add my own submit handler to the event of adding product to cart. I have tried: function activit_form_alter(&...
0
votes
0answers
17 views

Globally increase #maxlength attribute of textfield (form api)

I have thousabds of field for admin to edit data which is saved in db from mobile app. i can fetch those data into text field while editing but drupal having default #maxlength of 128 character but in ...
0
votes
0answers
13 views

Failing Form Validation replaces TextArea Field to 'Array'

I am creating a node by using standard node/add/content_type page. But for doing validation, I am using hook_form_alter(); If validation fails, I set error. //Other field on my form : ...
0
votes
0answers
19 views

Include node creation form error processForm

i've found this code on the net to include a node creation form on the net but i've this error : Warning: call_user_func_array() expects parameter 1 to be a valid callback, class 'Drupal\...
0
votes
1answer
25 views

How do i use hook_form_alter to set a default value for an entity reference?

$form['field_image']['#default_value']='default'; doesnt seem to be setting the default value. I Have content type called image and I'm trying to set the default value for a reference to it in ...
1
vote
1answer
36 views

Alter Ubercart Billing/Delivery Panes with User Profile Info

I'm trying to set a user's profile fields into the checkout process. A user must change these data only in own profile. The uc_addresses module is unsuitable for my needs. In the order form I need to ...
0
votes
1answer
14 views

Change labels of date select fields

I'm using the Form API to create a Date of Birth field with lists for month, day and year. $form['dob'] = array( '#type' => 'date_select', '#title' => t('Date of birth'), '#...
0
votes
1answer
24 views

Get submitted values of webform in hook_alter function

how can i get the submitted field values of webform in hook_alter function. One more question is how can i call to submit function from hook_alter function.
1
vote
1answer
39 views

How to make select option works like a button?

I have created a contact form by using webform module, in that I have added one component as reset and the type is select options. My requirement is when I choose this reset option from that dropdown ...
1
vote
0answers
41 views

I can't set a default value on hook_form_alter()

I have form alter for the user_register_form which is called. In this hook, I try to set a default value for a textfield but it doesn't work. I've tried all the syntax possible #default_value, #value, ...
1
vote
0answers
14 views

Add a non-system confirm popup on node add/edit

I want a custom confirmation popup to come up when someone wants to save a new node or update an existing one. Of course, the form only submits/saves info if the user clicks Yes. As it is now the ...
0
votes
1answer
29 views

hook_form_commerce_checkout_form_checkout_alter() changes are not reflecting on checkout page

I am trying to make the changes in commerce_checkout_form but I am facing some issues. Here is my hook_form_FORMID_alter : function MYMODULE_form_commerce_checkout_form_checkout_alter($form, $...
0
votes
1answer
82 views

How do I change the value of a button? [duplicate]

The value (label) of a button in a form that I want to modify is a Drupal\Core\StringTranslation\TranslatableMarkup object. The string is a protected value. How can I modify this string in ...
0
votes
2answers
75 views

How do I get the form ID with hook_form_alter()? [closed]

I tried putting the code below in my .module file but not getting anything displayed. Am I supposed to put anything else in the module file, or put this somewhere else? function ...
0
votes
0answers
10 views

Skip save of field collection attached to entity without removing reference to field collection?

I've got a node form encumbered with many field collections and node save takes forever. I would like to "lock" some of those field collections and forgo saving them on node save. Kind of like ...
1
vote
1answer
25 views

An invalid implementation mymodule_form_alter was added by hook_module_implements_alter

I am trying to have my module alter menu_ui functions. Changing my module's weight didnt help and I read that hook_module_implements_alter is the way to go. So, as described here I am appending my ...
1
vote
1answer
16 views

How to alter a form base on the users' request info?

I would like to customize a form base on the users' request info in a page callback. I use drupal_get_form (or node_add for node create form) to get the renderable array, but most changes to the array ...
2
votes
2answers
38 views

White screen of death in hook form alter

I have enabled simplenews module in drupal 8 and I am trying to reduce the width of input field from 60 to 30. I am trying to implement form alter hook and have devel module installed. I used dsm($...
0
votes
1answer
42 views

Alter form value in submit_preprocess

How do I change a value, in this case the title field of a node object form, in the preprocess function of the form_alter hook. $form['actions']['publish']['#submit'][] = MODULE_submit_preprocess'; ...
3
votes
3answers
58 views

How do I find a Form_ID for hook_form_FORM_ID_alter?

I want to alter the form for a content type I created for videos. The type is called Videos. How would I use hook_form_alter to alter the form to create the content?
0
votes
1answer
25 views

How to change “Save Draft” value on Webform?

I want to change the button text value from "Save Draft" to "Save". How can I target the button (CSS or custom module works for me)? I used to target forms like this: $form['actions']['submit']['#...
0
votes
1answer
22 views

How to hide form bulk operations for a specified user role in Drupal 8?

I have a view where I list user's own contents, this contains bulk operations. Users with "add article" permission can see this bulk operations thing but I would like to hide this bulk operations "...
0
votes
1answer
12 views

Hidden form values updated with multiple submission

I'm writing a backend validation function to prevent multiple submission for comments by logged in users in Drupal. Following is my code: function MYMODULE_form_comment_form_alter( &$form, &$...
1
vote
1answer
92 views

How do I change text on submit button in the node form?

I'm trying to change the submit button text "Save and keep published", but with no luck. I'm using standard hook_form_FORM_ID_alter like this: function mymodule_form_node_news_form_alter(&$form, ...
0
votes
1answer
52 views

Custom validation for views exposed form using form alter

I want to add my custom validation to the views exposed filter form for that I have added below code in hook_form_alter $form['#validate'][] = 'xxxx_custom_form_validate'; But its being called for ...
0
votes
1answer
23 views

Overriding field label

I'm trying to override the label of the picture field. I've started with the code here: How to change the field label on my registration form? Drupal 7 function mymodule_form_alter(&$form, &...
-3
votes
2answers
41 views

How I can alter this form using another module? [closed]

function client_form($form, &$form_submit) { $form['Client_name'] = array( '#title' => t('Client Name'), '#type' => 'textfield', '#value'=> nameget(), //'#required' =>...
1
vote
2answers
165 views

How to replace the search submit button with a Font Awesome character?

I would like to replace the search submit button with a Font Awesome character like the Magnifier (Search Icon) character, and put Search the site inside the search box. How can I achieve this?
3
votes
2answers
59 views

Add attribute to all textboxes in the site

The question is simple , in my theme I want to apply an attribute to all textboxes in whole forms . I know how to add an attribute to an specific element in drupal using hook_form_alter , but it is ...
0
votes
1answer
30 views

How can I tell Drupal to add autocomplete=off to the login form

I'm under pressure to close out some issues from a Qualys scan. One issue flagged was 150112 Sensitive form field has not disabled autocomplete Suggestions include adding autocomplete="off" to ...
1
vote
1answer
42 views

How to set multiple entity references as default values using the hook_form_alter()

I have a node which when renders an adds an entityform to the page. The node has a entity ref field which references multiple other nodes. (eg: Products A, Product B, Product C, etc) What I need is ...
1
vote
1answer
61 views

Is there a way to programmatically add questions to a webform grid?

I have seen hooks to use to alter webform options, but not the questions that appear on the left side of a grid. I would like those questions to be a node titles actually of a content type that I ...
0
votes
1answer
63 views

How to get value of Textarea in node add form?

In my node add form I have added one text area : function mymodule_form_alter(&$form, $form_state, $form_id) { if ($form_id == "contenttype_node_form") { if (!isset($node->nid) || ...
0
votes
0answers
22 views

How do I change field handler_settings within hook_form_alter?

I have an entity reference field that is inside of a field_collection (D8) and I need to alter it's views arguments during ajax load to pass in the value from a preceding field on the host entity. I ...
0
votes
0answers
11 views

How to alter a form for the translation of an entity?

Both hook_form_alter and hook_form_FORM_ID_alter in my module are getting triggered before the entityFormAlter in the ContentTranslationHandler. So the 'Delete Translation', which replaces delete is ...
0
votes
1answer
36 views

Add Legend to Text Format Fieldset

I'm working on making a site I maintain WCAG AA compliant. One of the items I'm getting flagged for is "Every FIELDSET element must contain exactly one LEGEND element." This error shows up on every ...
0
votes
0answers
28 views

Custom Vertical tab

I am adding a simple select element via form alter to the menu vertical tab on my nodes. In this select list the user can select an icon that should be displayed with the menu link. I have ...
1
vote
1answer
49 views

How do I modify a core field to use Ajax and add markup?

I am still getting the hang of D8... I have some entity types with various reference fields. I need to ajax in other values from another node type when changing the value of the entity reference ...
0
votes
2answers
54 views

Insert data in table using drupal form alter submit

I am currently work with a drupal's inbuilt form which is coming from it's system function. Now I added a extra field with value in the form with Drupal's custommodule_form_deal_node_form_alter(). It ...