php - 德鲁帕尔 6 : Programmatically Altering User Values

标签 php drupal drupal-6 profile

如何使用profile_save_profile?

foreach ($users as $user) { //list of users to act on
    $by_user = views_get_view_result('attendance', 'page_3', array($user->uid)); //view containing info about this user
    $edit = array('profile_attendance_short_term' => substr(count($by_user) / count($general), 0, 5)); //calculation

    profile_save_profile($edit, $user->uid, 'Fencing Information', TRUE); //update user profile???
}

我做错了什么?

编辑:这也失败了:

$edit = array('profile_attendance_short_term' => 9001);

profile_save_profile($edit, user_load(3), 'Fencing Information', TRUE);

最佳答案

我认为问题在于您将 $register (最后一个参数)指定为 TRUE。仅在创建新帐户时使用,因此如果设置,您将只能保存注册页面上可用的个人资料字段,这可能不是您想要的。

由于它不是必需参数,因此您可以将其省略。

当涉及到编辑格式时,如果值来自表单,则它期望与您所拥有的 $form_state['values'] 格式相同,例如:

<?php
$edit = array(
  'fencing_style' => 'Aggressive',
  'favorite_weapon' => 'sabre',
  'left_handed' => FALSE,
);
profile_save_profile($edit, $user, 'Fencing Information');

关于php - 德鲁帕尔 6 : Programmatically Altering User Values,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1291140/

相关文章:

javascript - Drupal.t 没有出现在翻译中

drupal - 如何禁用本地服务器上的安全页面?

php - GCM 显示错误请求实体太大错误 413

php - Isset 内联条件不起作用

php - 登录、 session 、用户管理、日志记录模块

drupal - 在多语言 drupal 中获取另一种语言首页的一般方法?

php - 使用 PHP 验证 Windows 8 购买(收据)

php - 在手机上使用 jQuery 更改背景图片 URL(使用内联 CSS 和 PHP 添加)

Drupal:父子可拖动表

php - 自动完成以及文本字段的拼写检查和复数检查