Drupal 6:将自定义字段放入数据库 [英] Drupal 6: Getting custom fields into the database

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

问题描述

我需要核心配置文件模块无法提供的自定义字段(从 SQL 查询填充的选择列表).我能够使用适当的选项成功添加该字段;但是,我不确定提交后如何处理这个新字段.

I needed a custom field that couldn't be provided by the core profile module (Select list populated from a SQL query). I was able to successfully add the field with proper options; however, I am unsure how to handle this new field once submitted.

据我所知,我需要编写一个函数来处理我的 SQL 插入,然后从 hook_form_alter 提交按钮调用该函数.

From what I understand, I need to write a function that handles my SQL insert, and then call that function from a hook_form_alter submit button.

截至目前,它只传递字段名称,而不是值.并且字段名称正在被序列化并存储在用户表的数据"字段中.我正在尝试将它传递给它自己的列.

As of now, it is passing only the field name, not the value. And the field name is being serialized and stored in the 'data' field of the user table. I'm attempting to pass it to its own column.

这是我的代码...

//takes value and inserts it to account field   
 function accountselect_submitaccount() {
        db_query( "INSERT INTO {user} (account)
                  VALUES {account_name}" );
      }

那么……

//call the above function using custom submit (I suspect this is the troubled area)
  function accountselect_form_alter(&$form, $form_state, $form_id) {
    if($form_id == 'user-register')
    $form['#submit'][] = 'accountselect_submitaccount';
  }

推荐答案

据我所知,只有在没有与字段名称匹配的列时,才会将新字段添加到 data 列中.您应该能够在用户表中创建一列 account,然后它就会填充该数据.

To my knowledge, new fields are only added to the data column if there's no column matching the field name. You should be able to just create a column of account into the user table and it'll get populated with that data.

至于您发布的代码,您的提交功能有很多问题:

As for the code you've posted, your submission function has a number of issues:

  • 提交函数采用包含提交值的函数.submit_function($form, &$form_state) 允许您访问 $form_state['values'] 数组.
  • INSERT 永远不会工作.您需要一个 UPDATE 查询.
  • 您不能在查询中执行 {account_name}.您需要实际使用 $form_state['values'] 中的值.
  • Submit functions take functions that include the submitted values. submit_function($form, &$form_state) gives you access to the $form_state['values'] array.
  • An INSERT will never work. You need an UPDATE query.
  • You can't do {account_name} in the query. You need to actually use the value from $form_state['values'].

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

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