简体   繁体   English

表单自动选择到特定的链接子域

[英]Form Auto select to specific link subdomain

I am trying to make it so when you select an option, it goes to a specific subdomain. 我试图做到这一点,所以当您选择一个选项时,它会转到特定的子域。 eg if coffee is selected, it should redirect to coffee.domain.com. 例如,如果选择了coffee,则应将其重定向到coffee.domain.com。 This is what I have, it seems to work but doesn't go to a chosen subdomain 这就是我所拥有的,它似乎可以正常工作,但没有转到所选的子域

<form>
<select name='http://domain.com' onchange='this.form.submit()'>
  <option selected>Select Option</option>
  <option value="coffee">Coffee</option>
  <option value="tea">Tea</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>

The code you posted is just HTML. 您发布的代码只是HTML。 There is no code there to actually do what you want. 没有代码可以实际执行您想要的操作。

If you wanted to do this in PHP you could try something like 如果您想在PHP中执行此操作,则可以尝试类似

<?php
    if(ISSET($_POST['domainSelect']) == 'coffee'){
        header('Location: http://www.domain-coffee.com');
    }
    if(ISSET($_POST['domainSelect']) == 'tea'){
        header('Location: http://www.domain-tea.com');
    }
?>

<form method="POST">
<select name='domainSelect' onchange='this.form.submit()'>
  <option selected>Select Option</option>
  <option value="coffee">Coffee</option>
  <option value="tea">Tea</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>

Or you could do it with JavaScript by doing something like 或者您可以通过执行以下操作来使用JavaScript

<script type='text/javascript'>
    function gotodomain(){
        var e = document.getElementById('domainSelectId');
        var strSelected = e.options[e.selectedIndex].value;

        if(strSelected == 'coffee'){
            document.location.href = 'http://domain-coffee.com'
        }

        if(strSelected == 'tea'){
            document.location.href = 'http://domain-tea.com'
        }
    }
</script>

<form method="POST">
<select id="domainSelectId" name='domainSelect' onchange='gotodomain()'>
  <option selected>Select Option</option>
  <option value="coffee">Coffee</option>
  <option value="tea">Tea</option>
</select>
<noscript><input type="submit" value="Submit"></noscript>
</form>

In either case I suggest you start thinking about what it is exactly you want and in what language its best to achieve in. 无论哪种情况,我都建议您开始考虑您真正想要的是什么,以及用哪种语言最好地实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM