Wednesday, November 30, 2011
howto initial fields on Drupal 7 node creation screen
hook_form_alter
===============
# to find the element you want to change
install devel
$ cd sites/all/modules
$ mkdir mymodule
$ cd mymodule
$ vi mymodule.info
name = mymodule
description = mymodule description
core = 7.x
$ vi mymodule.module
function mymodule_form_alter(&$form, &$form_state, $form_id)
{
// find out form_id you're interested
drupal_set_message($form_id);
}
function mymodule_form_{content-type-machnie-name}_node_form_alter(&$form, &$form_state)
{
// Prints a variable to the ‘message’ area of the page
dpm($form);
// print debuging infomation in order to find the element
drupal_set_message($form['field_remark']['und']);
// set default value as need
$form['field_remark']['und']['0']['value']['#default_value'] = 'hello';
}
$ drush en -y mymodule
http://drupal.org/project/prepopulate
======================================
allows fields in most forms to be pre-populated from the $_REQUEST variable.
Thanks
- http://drupal.stackexchange.com/questions/5605/how-do-you-identify-a-form-element
- http://drupal.org/node/1248914
- http://drupal.org/node/1137562
Labels:
Drupal7
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment