如何插入数据库Drupal自定义字段 [英] How to insert into database Drupal Custom Fields

查看:142
本文介绍了如何插入数据库Drupal自定义字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码检索内容类型

I retrieve content types with the following code

$form['ct'] = array(
  '#type' => 'checkboxes',
  '#options' => node_type_get_names(),
  '#title' => t('Hangi tür içerikler hakkında bilgi almak istersiniz?'),
);

它给出以下输出

http://i.stack.imgur.com/TOfS6.png

当我按下创建新帐户按钮时,POST数组如下:

And when I press Create new Account button, the POST Array is so :

http://i.stack.imgur.com/BtxhC.png

我的问题是如何将这些值插入数据库并读取?

My Question is How can I insert into database these values and read?

推荐答案

有有两种保存数据并将其与用户ID($ user-> uid)关联的方法。

There are two ways of saving this data and associates with user ID ($user->uid).


  1. 为用户添加新字段来自管理员/配置/人员/帐户/字段。假设新的字段名称是 ct,它是一个列表类型字段。在hook form_alter中,您可以将此选项分配给 ct。 Drupal将负责保存数据。

  1. Adding a new field for users from 'admin/config/people/accounts/fields'. Say the new field name is 'ct' and it is a list type field. In hook form_alter you can assign this options to 'ct'. Drupal will take care of saving the data.

您可以创建单独的表来保留此信息,并在hook hook_user_update中使用db_insert函数。要检索此信息,您需要在hook_user_load中使用db_query。

You can create separate table to keep this information and use db_insert function in hook hook_user_update. To retrieve this information you need to use db_query in hook_user_load.

这篇关于如何插入数据库Drupal自定义字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆