When a user browsing my website ends up on the 404 error page and tries to use the search, it loads the 404 error page again.

Upon inspecting the search block, the form action uses the current page. So in this case the action is the URL that landed the user on the 404 error page.

Example:

mydomain.com/test results in 404 error - then the form action for the search block will be set to /test

Since this URL is not valid - when the user searches from the 404 page, it returns to itself instead of /search/node/$keywords

Comments

certifiedGeek’s picture

I tried the following code in my template.php, but I think the action must be dynamically set somewhere else.

function MYTHEME_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'custom-search-blocks-form-1') {
    $form['actions']['#action'] = '/search/node/'; // Set the action
}
jdanthinne’s picture

Status: Active » Needs review
StatusFileSize
new678 bytes

Can you try the attached patch?

tarheeldev’s picture

I tested the patch and it appears to work. Thank you.

jdanthinne’s picture

Status: Needs review » Fixed

Great news. Thanks for the review.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

  • Commit 254a0c5 on 7.x-1.x by jdanthinne:
    Revert "[#2140129] fixed: Define the #action url for custom blocks"...
jdanthinne’s picture

Status: Closed (fixed) » Needs work

The patch broke the custom blocks for many user… that was not the correct solution then.

sylus’s picture

Has there been any progress on this issue as has been tripping me up as well. Was the only reason the previous patch removed because other search paths were being used?

jdanthinne’s picture

The reason to remove the parch was this issue: #2233325: upgrading to 1.14 breaks custom search block.
Being busy updating the module for D8, no progress has been made… but help is welcome.

vfranklyn’s picture

Hi there. I've run into this problem on my D7 site. Has there been any further development on this issue, by any chance? Is there something you could suggest I do on my end that might fix it? I know you are busy and it really is a terrific module, so thank you.

I'm completely unskilled in any sort of code contribution, so I'm sorry I can't help.

SDJH’s picture

Hi All, just run into this issue for my D7 website. Exactly the same problem as described above, has anyone made any progress on this? Not entirely confident using the above patch as it seems a bit risky.

tamer.kamel’s picture

StatusFileSize
new2.02 KB

To change the url of search result page from search/node/[key] to another like mysearch/[key] through custom search module there is function missing here to define the new url which is mysearch/[key] in the meny. you can create any module with hook hook_menu_alter or just add this path to custom search module.
I tested this well and I hope fixed the problem with you like me. welcome for any reply.

kmonty’s picture

Version: 7.x-1.12 » 7.x-1.x-dev
StatusFileSize
new1.29 KB

The patch in #12 did not work on my site. However, #2 did.

I realize the #2 patch broke sites--presumably because they did not have the path as defined. Here is a hybrid patch that combines the fix in comment #2 from @jdanthinne with some of the logic in #12 from @tamertama.

My attempt with this patch is to allow site owners to have different search paths other than search/node. I recognize this might not be perfect, but I hope it's a valuable starting point to resolve this issue.

kmonty’s picture

Status: Needs work » Needs review
loon’s picture

Status: Needs review » Closed (outdated)

D7 reached its EOL back in January 2025, and there is no active release for D7 for this module anymore.
Development or support is not planned for D7. All D7-related issues are marked as outdated in a bunch.

Everyone can apply the patch above (not tested by the community) to their D7 projects.
If the issue remains relevant for D10+ versions, merge requests with proposed solutions for a new module version (D10+) are welcome in a new follow-up issue.

Thanks!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.