[support] Normal search box form is send only there is #type => submit

Ivan Sergio Borgonovo mail at webthatworks.it
Fri May 30 08:35:02 UTC 2008


On Fri, 30 May 2008 01:32:17 +0200
Davide Michel 'ZioBudda' Morelli <michel at ziobudda.net> wrote:

> Hi all. I have the standard search  form . I have (via
> hook_form_alter) unset the $form['submit'] button and I have
> insert this
> 
>             //unset($form['submit']);
>             $form['search_block_form_keys']['#size'] = 18;
>             $form['sumbit2'] = array(
>                 '#value' => '>>',
>                 '#prefix' => '<div class="submit"><a 
> onclick="submitSearch();return false;" href="#">',
>                 '#suffix' => '</a></div>',
>             );
>             
>             drupal_add_js("
>             function submitSearch() { 
> document.getElementById('search-block-form').submit();
>             return false; }
>             ","inline");
>             break;
> 
> I have thinked that this worked (when click on the A TAG my 
> "submitSearch()" function is call)  but it si not true. The only
> way to make this works is to remove the //  before  unset()
> [first line of my code]
> 
> Why this ?

I think FAPI does some check on the existence of a '#type'=>
'submit'.
Furthermore to get the onClick event you don't have to wrap an anchor
around the button you'd just have to add attributes to the form
element.
Beware of the document.getElement... I'm not a js guru but it may
not work on all browsers (the DOM is not the same in IE/ffox), you'd
need a wrapper. I think all the JS goodies that comes with drupal
should have one.
Actually... if you dig into jQuery you may discover there is already
something ready to do exactly what you'd like in a more drupalish
way.

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it



More information about the support mailing list