문제

I am developing a Drupal module that will create a new user account as part of its functionality.

However, I would like to be able to include some fields that will be saved to the new user's profile when the user is created. This is easy enough for text fields, but I don't want to replicate the logic that's already been built for more complex fields.

Is there a way I can incorporate profile fields into my form using Fields API?

Thanks,

James

도움이 되었습니까?

해결책

You can use the field_attach_form() and field_attach_submit() functions for this:

function MYMODULE_form($form, &$form_state, $account) {
  $form['#account'] = $account;
  field_attach_form('user', $account, $form, $form_state);
}

function MYMODULE_form_submit($form, &$form_state) {
  field_attach_submit('user', $form['#account'], $form, $form_state);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top