Php 如何使用hook\u block\u view或其他工具为drupal 7中的自定义表单模块生成块视图

Php 如何使用hook\u block\u view或其他工具为drupal 7中的自定义表单模块生成块视图,php,drupal-7,drupal-modules,drupal-hooks,Php,Drupal 7,Drupal Modules,Drupal Hooks,我在drupal 7中使用hook_form()创建了一个表单,它可以作为我使用hook_menu()的页面访问,我需要将表单用作块。这是我的代码 function contact_form_form($form, &$form_state) { // $form['name'] = array( '#type' => 'textfield', //you can find a list of available types in the form api '#

我在drupal 7中使用hook_form()创建了一个表单,它可以作为我使用hook_menu()的页面访问,我需要将表单用作块。这是我的代码

  function contact_form_form($form, &$form_state) {  //     

 $form['name'] = array(
'#type' => 'textfield', //you can find a list of available types in the form api
'#title' => 'Name',
'#size' => 20,
'#maxlength' => 15,
'#required' => TRUE, //make this field required 
 );


 $form['mobileNo'] = array(
'#type' => 'textfield', //you can find a list of available types in the form api
'#title' => 'Mobile Number',
'#size' => 10,
'#maxlength' => 10,
'#required' => TRUE, //make this field required 
);

 $form['email'] = array(
'#title' => 'Email id',
'#type' => 'textfield' ,
'#required' => TRUE ,
 );

 $form['address'] = array(
'#title' => 'Address',
'#type' => 'textarea',
'#cols' => 60,
'#resizable' => TRUE,
'#rows' => 5,
'#required' => TRUE ,
  );   


 $form['image'] = array(
'#type' => 'file',
'#name' => 'custom_content_block_image',
'#title' => t('Block image'),
'#size' => 40,
'#description' => t("Upload a image.Only JPG, JPEG, PNG & GIF files are allowed."),
'#upload_location' => 'public://'
 ); 

 $form['submit_button'] = array(
'#type' => 'submit',
'#value' => t('Click Here!'),
  );

 return $form;
 }
//我使用的hook_submit()

   function contact_form_form_submit($form, &$form_state) {

   $target_dir = "uploads/";
   $target_file = $target_dir . basename($_FILES["custom_content_block_image"]["name"]);

   drupal_set_message('this is inside submit   
  drupal_set_message('this is inside submit 
  $fileName = $_FILES['custom_content_block_image']['name'];
  $tmpName  = $_FILES['custom_content_block_image']['tmp_name'];
  $fileSize = $_FILES['custom_content_block_image']['size'];
  $fileType = $_FILES['custom_content_block_image']['type'];

  $fp      = fopen($tmpName, 'r'); 
  $content = fread($fp, filesize($tmpName));
  $content = addslashes($content);
  fclose($fp);

  if(!get_magic_quotes_gpc())
  {
    $fileName = addslashes($fileName);
  }
在.install文件中创建的drupals数据库中插入所有获取的数据

      try {
     db_insert('contact_us')
  ->fields(array(
   'name' => $form_state['values']['name'],
   'mobile_no' => $form_state['values']['mobileNo'], 
   'email' => $form_state['values']['email'],
   'address' => $form_state['values']['address'],
   'image' => $content,
   'imageName' => $fileName,
   'imageSize' => $fileSize, 
   'imageType' => $fileType       
 ))
 ->execute();
 }
  catch (PDOException $e) {
  //print_r($e->getMessage());
  drupal_set_message('this is after db_insert <pre>'.print_r($e->getMessage(),true).'</pre>');
 }
试试看{
db_插入(“联系我们”)
->字段(数组)(
'name'=>$form_state['values']['name'],
'mobile_no'=>$form_state['values']['mobileNo'],
'email'=>$form_state['values']['email'],
'address'=>$form_state['values']['address'],
“图像”=>$content,
“imageName”=>$fileName,
“imageSize”=>$fileSize,
“imageType”=>$fileType
))
->执行();
}
捕获(PDO$e){
//打印($e->getMessage());
drupal_set_message('这是在db_insert.print_r($e->getMessage(),true)之后,'';
function contact_form_block_info() {
  $blocks['contact-form-block'] = array(
    'info' => t('My Block'),
    'cache' => DRUPAL_NO_CACHE
  );

  return $blocks;
}

function contact_form_block_view($delta = '') {
  $block = array();

  switch ($delta) {
    case 'contact-form-block':
      $block['subject'] = t('Contact Form Block Subject');
      $block['content'] = drupal_render(drupal_get_form('contact_form'));
  }

  return $block;
}
}
}

类似这样的内容:

大概是这样的:


,非常感谢,它成功了。我现在如何进行验证?我已经使用了
hook\u form\u validation()
,但是它没有验证块表单,非常感谢它的工作。我现在如何进行验证?我已经使用了
hook\u form\u validation()
,但它没有验证块表单