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 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作