By wydadi2003 on
Hello,
First, apologize if my question is stupid. I am new to Drupal, only a couple fo weeks.
I am developing a new block/module and would like to use drupal_set_content() function to display my query result, all this is in the _submit() function of my form.
until now, I was using drupal_set_message($content), but I want to display $content in the block content itself.
Any help is appreciated.
Thanks,
Comments
why this function
Why are you using this function? That's not the normal way to add content to a block.
Instead, you should define hook_block in your module, run the query, and return the output.
See, for example, comment_block or forum_block:
http://api.drupal.org/api/5/function/comment_block
http://api.drupal.org/api/5/function/forum_block
---
Work: BioRAFT
First Thanks for your
First Thanks for your response. I use the hook_block
-My SQL query is in the form_submit()
-The result is placed in global $variable.
- In the modulename_block, I call drupal_get_form() to have my form built and submitted,
- I put the result of drupal_get_form() into block['content']
I tried to use a block['content']=drupal_get_form().$variable to get the result displayed after the form , but it doesn't seem to work.
That's I was thinking of another way:
when using drupal_set_message($variable) , is fine, but not what I want.
when using drupal_set_content('content'/'left'...,$variable), I have nothing.
thanks,
like a preview?
So, if I understand you want something like a preview? The user "submits" the form and then the output is displayed in the block below the form?
If yes, here's how to do it:
1) define your "submit" button as type "button" NOT type "submit"
2) assign an "#after_build" function to your form
3) in the #after_build function you assign the output to the #suffix element of the form.
Thus, you would just have the block content as the usual drupal_get_form();
Below an example from one of my modules (in a page, not a block, but the concept is the same). This is similar to how the node or comment preview works. You might also want to look at that core code.
---
Work: BioRAFT
My form is a search form,
My form is a search form, and the result will be displayed below the form after the submit button is clicked.
I change the function form_submit to func1,
I change the type to button (not submit)
I have now $form['#after_build'] = array ('func1') (just 'func1 gives an error')
I assign the result of the query to $form['suffix']
But still not getting the result, worst now even the form is not displayed :(
oops- that code for 4.7
Oops- the code above is for 4.7- you should be returning $form for 5.x. Something like the below- see if you can get this code working.
---
Work: BioRAFT
Here's an example
I took a few more blocks out of this just to give an example, but this should be fully functional.
BTW, for your CSS, the blocks are named "pinkslip-block-0" and "pinkslip-block-1" by the block numbers in the "case 'list'."
Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database
NancyDru