我在一个块中创建了一个表单,第一次出现但它没有再次出现,我不知道为什么会发生这种情况,因为我对 drupal 还很陌生。
<?php
function my_module_block_info() {
$blocks = array();
$blocks['my_block'] = array(
'info' => t('My Custom Block'),
);
return $blocks;
}
function hook_block_view($delta = '') {
switch ($delta) {
case 'my_block':
$block['subject'] = t('My form');
$block['content'] = my_module_my_form();
}
}
function my_module_menu() {
$items = array();
$items['my_module/form'] = array(
'title' => t('My form'),
'page callback' => 'my_module_form',
'acess arguments' => array('access content'),
'description' => t('My form'),
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
return $items;
}
function my_module_form() {
return drupal_get_form('my_module_my_form');
}
function my_module_my_form($form) {
$form['name'] = array(
'#type' => 'textfield',
'#title' => t('username'),
'#required' => TRUE,
'#description' => "enter your username.",
'#size' => 20,
'#maxlength' => 20,
);
$form['picture'] = array(
'#type' => 'file',
'#title' => t('Image'),
'#description' => t('Upload a file, allowed extensions: jpg, jpeg, png, gif'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'update your profile',
);
return $form;
}
function my_module_my_form_submit($form, &$form_state) {
global $user;
$account = user_load($user -> uid);
$image_path = 'picture://';
$validators = array(
'file_validate_is_image' => array(),
);
$file = new StdClass();
$file -> uid = $user -> uid;
$file->uri = $image_path;
$file = file_save_upload('picture', $validators);
$new = array (
'name' => $form_state['values']['name'],
'picture' => $file,
);
user_save($account,$new );
$message = 'You have updated your profile';
drupal_set_message(t($message));
}
此表单正在更新用户名和用户图片,但是当我尝试在一个块中将此表单作为其内容调用时,但它在第一次后无法正常工作。请帮帮我。