Linked Questions

0
votes
0answers
20 views

Form API hook_form_alter not working [duplicate]

I am trying to set a default value using hook_form_alter on an entity form, and the usual thing I do is not working, can anyone see why? Here is the dsm($form) ... My module is called "pinboard" and ...
10
votes
3answers
35k views

Programmatically set the default value for a field

In Drupal 6, we could use PHP to set default values, but the same code cannot be used with Drupal 7. I am trying to do this through hook_form_alter(), but the code doesn't work. function ...
2
votes
1answer
10k views

How do I use hook_form_alter() to add CSS classes to a custom input field in user_register_form?

I want to add a CSS class to the input element of a custom field in my user_register_form. This is the field markup. <div class="field-type-text field-name-field-personal-best field-widget-text-...
3
votes
2answers
6k views

Adding validation to existing forms using #element_validate

Problem I'm using #element_validate to validate an input on a custom form which creates a node. I'm using element_validate_integer_positive as the function to validate. It works perfectly. It ...
0
votes
2answers
6k views

how to populate select list using hook_form_alter()?

I wanted to add values to a select list dynamically. Another module generates an array from a web service and I want to use those values to populate a select list in a form using hook_form_alter. I ...
3
votes
2answers
4k views

Update Entity Reference field programmatically

I'm kind of new to Drupal development and I'm a little lost on something I'm trying to do: My company has several locations and I am developing a method whereby each location can have their own page ...
1
vote
2answers
2k views

Change default Taxonomy value on form via form alter in D7

I am trying to alter a form with a taxonomy term select drop down field; I want to change the default term selected when the form loads. I'm altering the form array via hook_form_alter; however, my ...
2
votes
0answers
6k views

How would I change the label of a field in hook_form_FORM_ID_alter()?

For a Drupal 7 site, I'm trying to alter a form into multi-step and want to change the label of a field based on some answer from the first step, which is the reason for my question. I tried ...
1
vote
2answers
2k views

How to programmatically set a node field as empty?

I have some nodes of a content type with following fields: title body image I want to programmatically (!important) set the body field as empty (to make it like it was never set with any value). ...
0
votes
2answers
2k views

Alter the comment form

I have the following code to alter the way comment form is displayed. After the bellow code everything is displayed as i want to but it does not add the comments. global $user; if ($user->...
0
votes
2answers
2k views

Form - Submit hidden field (select)

Should be pretty straightforward but I am kinda stuck. I am prepopulating a mandatory field's value according to the URL, so I want to prevent the field from showing up, but not in a CSS level. hide()...
0
votes
2answers
2k views

Change the default value of the node reference via hook_alter_form

field_userid is a user reference field with an autocomplete widget i want to set the default value of this field, but the code below doesn't work Does anyone can help me? Thank you very much! ...
2
votes
3answers
1k views

PlaceHolder in comment Form

I want to add a placeholder to my all comment form , here is what i did : template.php function ThemeName_form_alter(&$form, &$form_state, $form_id) { if ($form_id == '...
0
votes
2answers
1k views

Drupal 7 hook_fom_alter not working for custom fields

I have added custom field for email address in my content type. I want to assigned default email address to this field. Following is my code. function request_order_form_alter(&$form, &$...
1
vote
2answers
1k views

Is it possible to change the field type in a node form afterwards?

I have an instance here where an existing textfield in a node form should be limited to enter only three possible values. I though it might be possible to alter the field to #type => 'select' and ...

15 30 50 per page