首页 > 解决方案 > 当用户单击 webform 弹出链接时,根据位置将用户重定向到特定网站

问题描述

我们在网站上有一个链接。

当用户点击链接时,它会弹出一个在线表格。

客户希望,如果来自美国以外的用户点击该链接,用户会被重定向到另一个网站。

这是可行的吗?

网站基于最新的 Drupal 8 版本,以防万一有一个模块可以做到这一点。

标签: javascriptphpredirecturl-redirectiondrupal-8

解决方案


您可以像这样使用表单使用 hook_form_ID_alter。

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
}

推荐阅读