-2

We have a link on a website.

When user clicks on the link, it pop ups an online form.

Customer wants that if a user from outside the USA clicks on that link, user gets redirected to another website.

Is this doable?

Website is based on latest Drupal 8 Version just in case there is a module that does that.

lupoll88
  • 150
  • 13
  • Possible duplicate of [Find user location using jQuery/JS (without google geolocation api)?](https://stackoverflow.com/questions/14177647/find-user-location-using-jquery-js-without-google-geolocation-api) – chevybow May 21 '18 at 17:42
  • You could check the IP of the request that generates the page with the link on it, use IP geolocation to determine where they are, and then generate a different link depending on where they are. – Nathan Hinchey May 21 '18 at 18:05

1 Answers1

0

You can use form use hook_form_ID_alter like this.

function hook_form_FORM_ID_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  // get the IP address of user and determine where they are coming from
  // Follow this https://stackoverflow.com/questions/12553160/getting-visitors-country-from-their-ip
  // Redirect user
  // Follow this https://drupal.stackexchange.com/questions/146185/how-to-create-a-redirection-in-drupal-8
}
nghale
  • 23
  • 6