function Mymodule_user($op,&$edit, &$account, $category = NULL) {
switch ($op) {
case 'register':
$result = db_query("SELECT id,name FROM {sites} ORDER BY name");
while($row=db_fetch_array($result)) {
$sites[$row['id']] = $row['name'];
}
$form['site_select'] = array(
'#type' => 'select',
'#title' => t('Select your site'),
'#options' => $sites,
)
return $form;
case 'insert':
//How to take the $form values from above and use in my query to
//write to my own table while writing to the standard 'users' table?
db_query("INSERT INTO {another_table} (site_name) VALUES ('%s')",
$form['site_select']);
);
当用户在创建标准 Drupal 帐户时点击提交按钮时,如何将自定义字段值 $form['site_select'] 传递给我的案例“插入”,以便我可以将其写入“another_table”。用户名和密码等常规用户数据需要继续写入默认的“用户”表。
问:为什么不像往常一样让 Drupal 序列化并将您的数据保存到 'data' 字段中的 'users' 表中?
答:因为我希望能够在另一个 Drupal 表单中进行 AJAX 化和使用自动完成功能,以及在 MySQL 中查询特定的自定义字段。MySQL 无法序列化/反序列化。例如,“SELECT DISTINCT site_name FROM another_table”