2017-08-01 81 views
1

我一直在做研究大约2天,但无论它不工作,或者我不知道脚本如何工作。如何根据表单数据重定向到页面?

我有一个HTML表单,action属性发布到我的电子邮件营销服务的URL。问题是,它重定向到我在表单设置中输入的URL(www.theirsite.com/myid/submissions/action所在的位置)。

我希望它重定向到不同的网址,具体取决于选中哪个单选按钮,但我只允许在所有提交中放入一个网址。

任何帮助,将不胜感激。我是编码新手,但了解基本规则。

预先感谢您!编辑: 这是我的表单代码。

<form action="https://www.getdrip.com/forms/19579582/submissions" method="get" data-drip-embedded-form="19579582" data-drip-id="19579582">

单选按钮:

<input name="fields[situation]" required="" type="radio" value="employed full time"> <input name="fields[situation]" required="" type="radio" value="employed part time"> <input name="fields[situation]" required="" type="radio" value="unemployed"> <input name="fields[situation]" required="" type="radio" value="retired"> <input name="fields[situation]" required="" type="radio" value="self employed">

按钮:

<button type="submit" name="submit" data-drip-attribute="sign-up-button">My Button Text</button>

+0

我们需要代码。你的帖子不清楚。 – William

+0

对php文件的操作=>在这个php文件中,检查你的按钮收音机。取决于将值重定向到您想要的页面。 – Bdloul

+0

如果您需要其他帮助,您需要发布一些代码。 – Difster

回答

0

所以你的问题是一个相当容易的解决。

当用户选择一个无线电框时,您需要更新<form action="www.theirsite.com/myid/submissions/">

这里是你可以在纯JS做什么:

<!-- So these inputs when clicked, will update your 'action' URL --> 
<input name="myRadioButton" required="" type="radio" value="employed-full-time" data-marketing="employed full time" onclick="updateFormAction(this)"> 
<input name="myRadioButton" required="" type="radio" value="employed-part-time" data-marketing="employed part time" onclick="updateFormAction(this)"> 
<input name="myRadioButton" required="" type="radio" value="unemployed" data-marketing="unemployed" onclick="updateFormAction(this)"> 
<input name="myRadioButton" required="" type="radio" value="retired" data-marketing="retired" onclick="updateFormAction(this)"> 
<input name="myRadioButton" required="" type="radio" value="self-employed" data-marketing="self employed" onclick="updateFormAction(this)"> 

<!-- This is the bit that lets you decide what type it is --> 
<input id="marketingValue" name="marketingValue" type="hidden" value="none" /> 

<script> 
    function updateFormAction(radioButton) { 
     // These 2 lines will update your forms ACTION URL 
     // If there is only one form on the page this will work 
     document.forms[0].action = radioButton.value 

     // Otherwise select the form you want to target using ID 
     document.getElementById('form-id').action = radioButton.value; 

     // This will update your hidden input value 
     document.getElementById('marketingValue').value = radioButton.getAttribute('data-marketing'); 
    } 
</script> 

,上面的代码会做你想要什么。每次用户点击单选按钮时,表单的action = {value}都会更新,因为它会调用updateFormAction()函数。

+0

谢谢,我会尝试!有没有办法让我的'价值'领域呢?我需要保留它们,以便我的电子邮件营销服务可以跟踪标签。欢呼 –

+0

对不起,你指的是哪个'value'字段? –

+0

单选按钮值。我用一些代码更新了我的问题,如果它没有任何指示灯 –

相关问题