0

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?

mrxzhu
  • 1
  • 1
  • just make /code/ an html file with a script tag, sniff the queryString using a GET parser or regexps, or a switch(), or whatever, and then set location.href to the desired target url to redirect. if you want your list of urls kept secret, sub php ($_GET) for js+html. – dandavis Mar 27 '14 at 05:17
  • Those are great words and I'm sure would be very helpful for a more code oriented person. As a designer I have to learn a lot of the basics. What keywords should I search for to better understand how to use PHP $_GET for this project? – mrxzhu Mar 27 '14 at 19:07
  • $_GET, php redirect, php switch. basically, it's like switch($_GET['code']){ case '12345': redirect('/page/red.html'); case '54321': redirect('/page/blue.html'); }... now, the redirect() function isn't real, but it can be made in a line or two of code from your "php redirect" google... if you post a non-working version, we can help fix it. – dandavis Mar 27 '14 at 20:24

0 Answers0