dongshan4878 2015-12-04 16:50
浏览 89
已采纳

检查表单中单选按钮的值后更改变量URL

I got this form. They added a radio button selection. Now I would like the url behind the submit button to change depending on which radio button is selected. So every choice gets his own url and so it's own page. (this is needed for analytics) I am not very well know with php but it seems there is a way but can't get it to work.

<form id="contact-form" action="<?php echo SITE_URL; ?>/trial-email.php" class="contact-form" method="post">
  <input type="hidden" name="locale" value="<?php echo $locale->language; ?>">
  <input type="hidden" name="button" value="<?php echo $_GET['button']; ?>">            
  <input id="text1" type="text" name="company" placeholder="Company name" />
  <input id="text2" type="text" name="name" placeholder="Name>" />
  <input id="email1" type="email" name="email" placeholder="Email" />
  <input id="tel1" type="tel" name="phone" placeholder="Phone" />

   <div class="how-find-us">
     <span class="how-title">How did you find us?</span>
     <input class="how-radiobutton" type="radio" name="howbutton" value="Online advertisement" checked>Online advertisement
     <input class="how-radiobutton" type="radio" name="howbutton" value="Google">Google
     <input class="how-radiobutton" type="radio" name="howbutton" value="A Friend told me">A Friend told me
     <input class="how-radiobutton" type="radio" name="howbutton" value="Other">Other
   </div>

  <input id="captcha" name="captcha" type="text" placeholder="<?php __translate('Fill in the characters'); ?>" />
  <div class="captcha_image" >
     <?php
      $_SESSION['captcha'] = simple_php_captcha();
      echo '<img src="' . $_SESSION['captcha']['image_src'] . '" alt="CAPTCHA" />';
    ?>
   </div>

  <span class="submit-holder"><input id="submit" class="btn" type="submit" value="<?php __translate('Get trial'); ?>"/></span>
</form>

I tried the code below but it did not work, it even broke the page.

<form action="" method="post">
  <input class="how-radiobutton" type="radio" name="howbutton" value="Online advertisement" checked>Online advertisement
  <input class="how-radiobutton" type="radio" name="howbutton" value="Google">Google
  <input class="how-radiobutton" type="radio" name="howbutton" value="A Friend told me">A Friend told me
  <input class="how-radiobutton" type="radio" name="howbutton" value="Other">Other
<span class="submit-holder"><input id="submit" class="btn" type="submit" value="get trial"/></span>
</form>

<?php
if (isset($_POST['submit'])) {
if(isset($_POST['radio']))
{
echo "You have selected :".$_POST['radio'];  //  Displaying Selected Value
}
?>

I read that it is possible to use the $_GET because that saves info in the url?!

</div>
  • 写回答

2条回答 默认 最新

  • duanba8070 2015-12-04 16:53
    关注

    Check this,

    if(isset($_POST['radio']))
    {
        echo "You have selected :".$_POST['radio'];  //  Displaying Selected Value
    }
    

    This should be howbutton

    if(isset($_POST['howbutton']))
    {
        echo "You have selected :".$_POST['howbutton'];  //  Displaying Selected Value
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器