I'm using custom search module for the advanced search on my website. The advanced search by criteria (phrase) and content types are being used. I wanted to customize the search form then I created a custom module and implemented the hook_form_alter
for customizing the search form.
<?php
MYMODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'custom_search_blocks_form_1') {
...
// for some reasons I want to hide the criteria phrase field
$form['custom_search_criteria_phrase']['#type'] = 'hidden';
...
}
}
?>
The code above doesn't work. I always have the criteria field showed in my advanced search form, so I use var_dump($form)
for looking into the $form
variable, I found that there is no custom_search_criteria_phrase
key in search form.
So I'm wondering maybe the custom_search_form_alter
function overwrote my search form?
How can I do it correctly?
Thanks in advance.
Comment | File | Size | Author |
---|---|---|---|
#3 | advanced_search_form.png | 6.2 KB | kuangshi.yan |
Comments
Comment #1
kuangshi.yan CreditAttribution: kuangshi.yan commentedAlso I cannot modify the field weight in
hook_form_alter
I think this is the same issue, there is no
#weight
key in$form
variable.Comment #2
jdanthinne CreditAttribution: jdanthinne commentedI don't understand why you want to change that with a module a hook_form_alter, because those options are configurable in the block option page itself (weights, criteria…). That's why Custom Search was created in fact…
Comment #3
kuangshi.yan CreditAttribution: kuangshi.yan commentedIn fact, I don't want to display the search box field and search criteria phrase field at the same time. Instead of that I will add a checkbox to the advanced search form. When unchecked, the search box will display, in contrast, when checked, it's the search criteria phrase will display. So I want to alter the form for hiding/showing fields.
Comment #4
jdanthinne CreditAttribution: jdanthinne commentedOk, I see.
I think your form_alters don't work because they are ran before Custom Search. On install Custom Search changes its weight to 100, so you need to have a heavier weight.
Try putting this in you module.install file (and uninstall and re-install it):
Comment #5
kuangshi.yan CreditAttribution: kuangshi.yan commentedOk, I see,
`weight` => 100
has been set for custom search module.May I know why you set a weight for your module?
Thanks.
Comment #6
jdanthinne CreditAttribution: jdanthinne commentedBecause it has to run after all the module that already alters the search.
Comment #7
kuangshi.yan CreditAttribution: kuangshi.yan commentedThanks. I pass the status closed for this issue.