How to insert into database Drupal Custom Fields

半腔热情 提交于 2019-12-13 04:43:30

问题


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?'),
);

And It gives the following output

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

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?


回答1:


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

  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.

  2. 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.



来源:https://stackoverflow.com/questions/26039974/how-to-insert-into-database-drupal-custom-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!