Skip to content

Latest commit

 

History

History

redirect-users-based-on-input-codes

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Redirect users based on input codes

Tags: Redirects

Use this task to prompt your users for a code, redirecting them to an appropriate destination based on what they enter. Some assembly required, with sample Javascript and HTML provided. :)

Default options

{
  "redirects_and_codes__keyval_multiline": {
    "/pages/secret-one": "one\num\nuno",
    "/pages/secret-two": "two\ndois\ndos",
    "/pages/secret-three": "three\ntrês\ntres"
  },
  "require_case_sensitive_codes__boolean": false,
  "invalid_code_message__required": "That code wasn't valid - try again."
}

Learn about task options in Mechanic

Documentation

Use this task to prompt your users for a code, redirecting them to an appropriate destination based on what they enter. Some assembly required, with sample Javascript and HTML provided. :)

Configure this task by filling in redirect URLs on the left, and a series of codes for each redirect on the right. The intent is to route users to the appropriate redirect, based on the code they enter.

This task doesn't run automatically. Instead, it generates some Javascript that's automatically embedded into your online storefront, redirecting the user when they enter a code that matches one of the redirects you've configured.

You can prompt the user for a code yourself, and pass the result to the function attemptRedirectByCode, like this:

<script>
  attemptRedirectByCode(prompt('Enter your code here:'))
</script>

Or, modify this HTML to set up a form for your users:

<form id="redirect-form">
  <input type="text" placeholder="Enter your code here">
</form>
<script>
  document.getElementById('redirect-form').onsubmit = function (event) {
    event.preventDefault();
    var input = event.target.children[0];
    attemptRedirectByCode(input.value) || input.select();
  };
</script>

Installing this task

Find this task in the library at tasks.mechanic.dev, and use the "Try this task" button. Or, import this task's JSON export – see Importing and exporting tasks to learn how imports work.

Contributions

Found a bug? Got an improvement to add? Start here: ../../CONTRIBUTING.md.

Task requests

Submit your task requests for consideration by the Mechanic community, and they may be chosen for development and inclusion in the task library!