Hey just one quick question/feature request. There may be an obvious way to do this, but I am stumped.

Documentation only lists a way to put all "left" blocks on the left, and "right" blocks on the right (I already modded xsilver to work for my site's style) - but what if I have a split header for my page (graphics on left, dynamic content on the right) and I want to offer the search block on the right half if a user is logged in, and a login block there if they aren't? I sniped the code out for a search and that appears there now ( linux.trustdevelopment.com ) but I don't want it to appear for users that aren't logged in, since I want searching to be one of the "premium services" that a person would want to register an account for...

Thanks...
Josh

Comments

al’s picture

Component: Node system » Modules

You need to create a search.module that puts a search box in a block, using the already existing search permission to determine whether users can access it (i.e. it gets displayed) or not.

I'm moving this to a contribs feature request. Maybe someone will want to implement it for you. It would be really trivial to do...

al’s picture

Title: A PHP function to echo a block up top... » Search module should have a simple search block
Component: Modules » search.module
Priority: Normal » Minor

After some thought, I've decided that having the search module able to put a simple search text box in a block with a "search" button would be a useful thing to do. I'm therefore reassigning the project, etc. for this and changing the summary to reflect this.

This would be really very easy to implement. Anyone?

erikhopp’s picture

hey.

ok, so i don't really know php and i haven't really played with the drupal core too much, so maybe it's not right, but i think i have created a block for the search module.

it works on my site (i think). the only problem is that i just cannot figure out how to change the size of the input box. it is set at 50 for the search page, but i can't seem to figure out where that value is set (and i feel like i have looked everywhere).

so if someone can change that, i think this feature request is done.

oh - and i still have not spent the time to figure out how to add stuff via cvs so the search module is here: http://mediamutiny.org/search.module

and i updated the $id. i'm not sure if i am supposed to do that or not.

i hope this helps...

erik.

al’s picture

Assigned: Unassigned » al

Your module looks like it returns the search results inside the block, which isn't quite what's wanted. This is actually a bit of a mess - the search_form function should be able to do what we want, but you can't actually use it due to various issues (like the width).

I note that the xtemplate theme uses its own search form. I'm sending a patch to the mailing list that does the same thing.

BTW, the $Id: $ field in files is generated automatically by the CVS server. Don't alter it yourself - it'll make us all terribly confused...

al’s picture

A patch to implement this has been sitting in my sandbox for ages. Dries - is there something wrong with the patch? Or do you just not think this to be a valid feature request? Should it be done with a completely seperate module? Or be theme-specific?

erikhopp’s picture

so what is the status of this search block patch? i'd like to see it added if it works ok.

erik.

erikhopp’s picture

one more attempt to get this committed...

the patch is still in al's sandbox...

i have it enabled on one of my sites and it works great...

erik.

kristen pol’s picture

I need a search block so I'm writing one right now, but maybe you guys have one floating around already??? If so, where is it? :)

Thanks,
Kristen

gordon’s picture

Actually when ever I need a search block I actually just create a custom block and I have never had a problem, see below.

<form action="index.php?q=search" method="post">
  <br />
  <input type="text" class="form-text" size="15" name="keys" />  
  <input type="submit" class="form-submit" value="Search" />
</form>
erikhopp’s picture

Assigned: al » erikhopp
StatusFileSize
new1.02 KB

here is a patch that adds a search block. works with 4.4.x and should work with HEAD too.

moshe weitzman’s picture

In order to mark an issue as 'patch', please submit a patch against HEAD and test it. Moving back to Active.

Also, consider using the form_x functions instead of hard coding HTML into the block.

pfaocle’s picture

Apologies for not including a patch here, but for anyone who's interested, here's my amendment to erikhopp's patch (using drupal's form functions as suggested):

function search_block_view() {
	$output .= form_textfield( $title='Search in this site', $name='keys', $value='', $size=15, $maxlength=128 );
	$output .= form_submit( $value="Go" );
	return "<div class=\"search-block\">". form($output, "post", url("search")) ."</div>";
} 
erikhopp’s picture

Priority: Minor » Normal
StatusFileSize
new764 bytes

ok. thanks leafish_paul.

here is a patch that applies to HEAD.

erikhopp’s picture

forgot to set to patch...

dries’s picture

The patch looks incomplete to me. You have to implement 'search_block()' for this work ...

Steven’s picture

The patch is incomplete and uses borky code (the whole $var=value thing in the search block function is theoretically correct, but practically stupid). Perhaps the current search_form function should simply be modified with a width parameter so it can be used in the block too?

tangent’s picture

StatusFileSize
new1.61 KB

The attached patch adds a hook_block and uses search_form to add the form to the block. I've extended the search_form function so that modules can alter the text prompt as having the prompt visible in a block looks bad.

I created this patch prior to searching for this issue to apologies to those who have put in work on this.

Steven’s picture

I committed a modified patch to HEAD:

- Added doxygen for the $prompt variable
- Changes search block info from "Search" to "Search form"

Anonymous’s picture