开发者

Proper handling of form select list to rewritten URLs

开发者 https://www.devze.com 2023-02-08 20:02 出处:网络
I have a homepage spec requiring two small forms, each with a <select> that allows a user to choose one of a 开发者_运维百科number of \"subjects\" or \"tags\" and then be taken to a URL that loo

I have a homepage spec requiring two small forms, each with a <select> that allows a user to choose one of a 开发者_运维百科number of "subjects" or "tags" and then be taken to a URL that looks like http://example.com/subjects/selected-subject or http://example.com/tags/selected-tag. Internally, these rewritten URLs are actually http://example.com/index.php?view=tags&id=selected-tag.

If not for the rewritten URLs, I would do a straightforward GET from the form. However, I'm now looking for a best practice way of implementing these in an accessible manner.

My first thought is to do a post-redirect-get to simply translate the form fields into a the beautified URL, but I'm wondering if there's another way to do this without requiring the intermediary redirect page.

My gut tells me to use the PRG, but I wonder if it can be done properly with javascript. For accessibility reasons, I would rather not bind the <select> onchange to load the destination page. Would it still be accessible if I instead bound the <submit> onclick to change window.location.href rather than truly submitting the form?


Best to implement both. Having javascript redirect the user using window.location.href is faster. For users with javascript disabled, the form will still work via PRG.

0

精彩评论

暂无评论...
验证码 换一张
取 消