Query String Redirection: How to change form input

2019-09-17 15:20发布

Right now I am working on a project to create a very basic combination lock style navigational form where inputting different codes takes you to specific URLs. (This is only for a puzzle so it doesn't have to be secure.)

I created a simple keypad with an HTML form (itself derived from this old forum post) which uses a basic GET method to append a query string like ?code=ABC123 to a specified URL.

Current working keypad demo in CodePen.

Now I would like to be able to parse the output in such a way that entering a specific code takes you to a corresponding page. I looked at ways to manage this kind of action with Python/Perl/CGI, PHP, Ruby on Rails... and I see I just need to craft a very simple script that checks the code against an array with some simple logic like this:

  • If string is ABC123, go to /page/here.html
  • If string is FF0000, go to /page/red.html
  • (etc.)
  • If string is anything else, go to 404.html (or better, show an error and not leave the page at all.)

I feel really close since I'm already consistently producing a ?code=XXXXXX from this form, I just can't figure out how to turn that into actually performing the action of directing the visitor away from the keypad and toward a page whose code they just entered. The answer seems really obvious to me but after several hours of fiddling I haven't hit upon the right answer. I'd prefer to do this in JavaScript or a PHP script.

How do I go about creating this behavior?

0条回答
登录 后发表回答