Hi!
I'm pretty new to Drupal and I've only played with making my own modules for a short time. The API seems very clear and straightforward, and the documentation and examples are excellent. However, what I'm now trying to do requires me to combine things in a way that isn't covered in the docs. I need to ask for advice from someone with more experience.
Here's what I want to do:
- In my module, I export two blocks, let's call them A and B.
- Block A should include the user's details (let's say, login and full name) and a drop-down menu with items that belong to that user.
- Block B should show the details of whatever was selected in the drop-down menu.
I guess I need to get the user's details using $user->uid, $user->name and so on. Am I correct in assuming that I can use the form generation functions to make the dropdown even if I'm making a block?
Finally, and most importantly, what is the recommended way of signaling to block B what was selected in block A? Using variable_[get,set] is probably not the right way. How about a cookie? Or can I read the state of the form in block A from block B?
I'm using Drupal 4.6.3.
I'd be glad for any advice!
Comments
Re: Block content based on selections in another block
Nobody replied but I managed to figure this out on my own. I'm replying to myself in the hope that someone else will find this useful.
The form data gets stored in $_REQUEST['edit'], so you can make a form like this and have it retain its state:
This code is supposed to be placed in a function that generates a block. When that form is submitted, it will have the previously selected value pre-selected instead of the browser default (the first option).
In the same way, you can access the state of another form from a different block, which was what I wanted to do. You just have to remember that the first time around, the $_REQUEST['edit'] variable will not be set, so you have to make a special case for that or have the logic work without the variable set.