dongshan4878 2015-12-04 16: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 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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀