dongshan4878 2015-12-04 08:50
浏览 91
已采纳

检查表单中单选按钮的值后更改变量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 08: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部