On Fri, 30 May 2008 01:32:17 +0200 Davide Michel 'ZioBudda' Morelli michel@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"><aonclick="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.