使用自定义模块,显示结果,

发布于 2024-09-30 13:07:13 字数 1749 浏览 2 评论 0原文

function searchsong_block($op='list',$delta=0){
 $block = array();
 switch($op){

  case "list":
   $block[0][info] = t('Search song');
   return $block;
  case "view":
   $block['subject']='THIS IS SONG SEARCH MODULE';
   $block['content']=drupal_get_form('custom1_default_form');
   return $block;

 }




} 

function custom1_default_form () {
 $form = array();
  $form['txt_name']  =
    array('#type' => 'textfield',
          '#title' => t('Please enter your name'),
          '#default_value' => variable_get('webservice_user_url',''),
          '#maxlength' => '40',
          '#size' => '20',
          );

  $form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Save Details'),
   );  

  return $form;   

  }

  function custom1_default_form_validate (&$form, &$form_state) {

    if(($form_state['values']['txt_name']) == '') {
        form_set_error('user_webservice', t('Enter a name'));
    }
  }

  function custom1_default_form_submit ($form_id, $form_values) {
  $GET_TXT_VAL = $_POST['txt_name'];
  $result = db_query('SELECT title FROM {node} WHERE type = "%s" AND title LIKE "%%%s%%"', 'song', $GET_TXT_VAL);
  $output='';
  while ($row = db_fetch_object($result)) {
   // drupal_set_message($row->title);----IF I ENABLE THIS LINE THEN MY SEARCH RESULT DISPLAYING IN THE GREEN BLOCK, YES I KNOW THIS FUNCTION SOMETHING LIKE ECHO JUST FOR TESTING PURPOSE WE SHOULD USE
    $output .=$row->title;
  }
  $block['content'] = $output;
 }

如何打印我的输出,

上面的模块不显示任何内容,甚至也显示错误,

我想我应该使用主题('itemlist')一些东西,但我不确定如何使用它,以及我应该在哪里使用它,

那么我应该做什么想要的是,我想显示我的搜索结果,在内容区域,

请在下面找到我的问题图片视图。 替代文本

function searchsong_block($op='list',$delta=0){
 $block = array();
 switch($op){

  case "list":
   $block[0][info] = t('Search song');
   return $block;
  case "view":
   $block['subject']='THIS IS SONG SEARCH MODULE';
   $block['content']=drupal_get_form('custom1_default_form');
   return $block;

 }




} 

function custom1_default_form () {
 $form = array();
  $form['txt_name']  =
    array('#type' => 'textfield',
          '#title' => t('Please enter your name'),
          '#default_value' => variable_get('webservice_user_url',''),
          '#maxlength' => '40',
          '#size' => '20',
          );

  $form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Save Details'),
   );  

  return $form;   

  }

  function custom1_default_form_validate (&$form, &$form_state) {

    if(($form_state['values']['txt_name']) == '') {
        form_set_error('user_webservice', t('Enter a name'));
    }
  }

  function custom1_default_form_submit ($form_id, $form_values) {
  $GET_TXT_VAL = $_POST['txt_name'];
  $result = db_query('SELECT title FROM {node} WHERE type = "%s" AND title LIKE "%%%s%%"', 'song', $GET_TXT_VAL);
  $output='';
  while ($row = db_fetch_object($result)) {
   // drupal_set_message($row->title);----IF I ENABLE THIS LINE THEN MY SEARCH RESULT DISPLAYING IN THE GREEN BLOCK, YES I KNOW THIS FUNCTION SOMETHING LIKE ECHO JUST FOR TESTING PURPOSE WE SHOULD USE
    $output .=$row->title;
  }
  $block['content'] = $output;
 }

How to print my output ,

Above module does not display anything , even error also,

i thing i should use theme('itemlist') somthing , but i am not sure how to use this , and where i should use this ,

So what i want is , i want to display my search result , in the content region ,

Please find my question picture view below..
alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦断已成空 2024-10-07 13:07:14

验证和提交不是为了输出数据。
您应该以 custom1_default_form 形式显示结果:
添加提交 $_SESSION['search_text'] 或使用多步“存储”(为此学习 drupal 表单 api)。
但让我们看看如何通过会话进行工作:
在custom1_default_form中添加:

// Here is your form code, so form will appear on the top
// ...
if (isset($_SESSION['search_text'])) {
  //add here your code from submit that output searching result
  $form['result'] = array(
    '#type' => 'item',
    '#value' => $output,
  );
  unset($_SESSION['search_text']); // don't forget clear session
}

您的提交函数应该是这样的:

function custom1_default_form_submit($form, &$form_state) {
  $_SESSION['search_text'] = $form_state['values']['txt_name']; 
  // this will store text field into session, then reload page, 
  // so you drupal_get_form will see entered values.
}

这就是全部。

提示:

if(($form_state['values']['txt_name']) == '') {
    form_set_error('user_webservice', t('Enter a name'));
}

如果需要,则不需要此代码:

  $form['txt_name'] = array(
   ... // other properties
   '#required' => true,
  );

请在此处阅读有关表单API的信息:http://api.drupal.org

使用块的其他方式,只需通过 drupal_get_form 调用输出结果和表单的函数即可,因此:

...
$block['content']='custom1_default_result';
...
function custom1_default_result () {
  $output .= drupal_get_form('custom1_default_form');
  ...
  $output .= //search result if session filled/
} 

Validate and submit are not for outputting data.
You should show your results in custom1_default_form:
Add in submit $_SESSION['search_text'] or use multistep "storage" (learn drupal form api for this).
But let's look how to work via sessions:
Add in custom1_default_form:

// Here is your form code, so form will appear on the top
// ...
if (isset($_SESSION['search_text'])) {
  //add here your code from submit that output searching result
  $form['result'] = array(
    '#type' => 'item',
    '#value' => $output,
  );
  unset($_SESSION['search_text']); // don't forget clear session
}

Your submit function should be like this:

function custom1_default_form_submit($form, &$form_state) {
  $_SESSION['search_text'] = $form_state['values']['txt_name']; 
  // this will store text field into session, then reload page, 
  // so you drupal_get_form will see entered values.
}

This is all.

Tips:

if(($form_state['values']['txt_name']) == '') {
    form_set_error('user_webservice', t('Enter a name'));
}

This code is not needed, if you do:

  $form['txt_name'] = array(
   ... // other properties
   '#required' => true,
  );

Read please about form api here: http://api.drupal.org

Other way to use block, just call function that output result and form via drupal_get_form, so:

...
$block['content']='custom1_default_result';
...
function custom1_default_result () {
  $output .= drupal_get_form('custom1_default_form');
  ...
  $output .= //search result if session filled/
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文