English 中文(简体)
• 如何在方案一级为用户概况增加新的领域
原标题:How to add new fields to user profile in Drupal 7 programmatically

I want to develop a module that add fields to user profile in drupal 7, like phone number and CV ... and I don t know how to do that (using Database or using fields API) pls help me.
Any clear tutorials will be appreciated.

最佳回答

遵循以下守则

    $myField_name = "NEW_FIELD_NAME";
    if(!field_info_field($myField_name)) // check if the field already exists.
    {
        $field = array(
             field_name     => $myField_name,
             type           =>  text ,
        );
        field_create_field($field);

        $field_instance = array(
             field_name     => $myField_name,
             entity_type    =>  user , // change this to  node  to add attach the field to a node
             bundle         =>  user , // if chosen  node , type here the machine name of the content type. e.g.  page 
             label          => t( Field Label ),
             description    => t(  ),
             widget         => array(
                 type       =>  text_textfield ,
                 weight     => 10,
            ),
             formatter      => array(
                 label      => t( field formatter label ),
                 format     =>  text_default 
            ),
             settings       => array(
            )
        );
        field_create_instance($field_instance);

希望...... Muhammad。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签