新しいユーザーを作成し、そのユーザーの多数のカスタム フィールドに入力するカスタム フォームがあります。これらのフィールドの 1 つはカスタム イメージです (システム アバター イメージではありません)。
フォームを介してサーバーにアップロードされた画像を取得できますが、適切なフィールドに画像を取得できません。これまでの私の(カスタムモジュール)コードは次のとおりです。
function newacc_freebusiness_form($form, &$form_state) {
$form['bussimage'] = array(
'#title' => t('Upload an image that shows off your business.'),
'#type' => 'managed_file',
'#description' => t('Max size of 3Mb and filetype of jpg jpeg or png'),
'#upload_location' => 'public://bussimages/',
'#upload_validators' => array(
'file_validate_extensions' => array('png jpg jpeg'),
'file_validate_size' => array(3*1024*1024),
),
'#required' => TRUE,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
$form['#validate'][] = 'newacc_freebusiness_validate';
return $form;
}
function newacc_freebusiness_validate($form, &$form_state) {
$bussimage = $form_state['values']['bussimage'];
$file = file_load($bussimage);
$bussimage = image_load($file -> uri);
image_save($bussimage);
$bussimage = image_load($file -> uri);
$edit = array(
'name' => 'name',
'mail' => 'mail@mail.com',
'status' => 0,
'language' => 'en',
'init' => 'mail@mail.com',
'roles' => array(8 => 'Promoter'),
'field_business_image' => array(
'und' => array(
0 => array(
'value' => $bussimage,
),
),
),
);
user_save(NULL, $edit);
}
これはエラーメッセージをスローしています:
Notice: Undefined index: fid in file_field_presave() (line 219 of /var/www/drupal_site/modules/file/file.field.inc).
私は今、非常に多くのトリックを試し、ググりすぎたので、自分が持っているものと試していないものを説明することさえできません!
助けてください。