如何在表单drupal 7中添加图像字段

pkm*_*pkm 2 php image drupal-7

我正在创建一个如图所示的表单,它通过将 php 代码放在 body 块中,将细节保存在后台的 csv 中,这工作正常,但谁能告诉我如何在表单中添加图像上传选项并将其保存在其他地方

在此处输入图片说明

Pra*_*nse 5

首先不要在正文块中添加代码。创建自定义模块。

要添加图像字段,请参阅Drupal Form API

例如。

$form['image_example_image_fid'] = array(
  '#title' => t('Image'),
  '#type' => 'managed_file',
  '#description' => t('The uploaded image will be displayed on this page using the image style choosen below.'),
  '#default_value' => variable_get('image_example_image_fid', ''),
  '#upload_location' => 'public://image_example_images/',
);
Run Code Online (Sandbox Code Playgroud)