你在这里

添加自定义字段到用户注册表单方法

主标签

<?php
/**
 * Implementation of hook_enable().
 */
function addexample_enable() {
  // Check if our field is not already created.
  if (!field_info_field('field_myfield')) {//--字段名称需要小写
    $field = array(
        'field_name' => 'field_myfield', 
        'type' => 'text', 
    );
    field_create_field($field);

    // Create the instance on the bundle.
    $instance = array(
        'field_name' => 'field_myfield', 
        'entity_type' => 'user', 
        'label' => 'My Field Name', 
        'bundle' => 'user', 
        // If you don't set the "required" property then the field wont be required by default.
        'required' => TRUE,
        'settings' => array(
           // Here you inform either or not you want this field showing up on the registration form.
            'user_register_form' => 1,
        ),
        'widget' => array(
            'type' => 'textfield',
            'weight' => '1',
        ), 
    );
    field_create_instance($instance);
  }
}
?>

 

http://drupal.stackexchange.com/questions/8253/how-to-add-extra-fields-to-user-profile

Drupal 版本: 

猜你喜欢

my_filed.jpg

试试看,不要轻言放弃!

weight用来控制字段显示的位置

试试看,不要轻言放弃!