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

时间:2015-12-04 16:50:01

标签: php html forms post

我收到了这张表格。 他们添加了单选按钮选择。现在,我希望提交按钮后面的URL可以根据选择的单选按钮进行更改。所以每个选择都有他自己的网址,所以它是自己的网页。 (这是分析所需的) 我对php不太了解,但似乎有一种方法,但无法让它工作。



<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>
&#13;
&#13;
&#13;

我尝试了下面的代码,但它没有用,甚至打破了页面。

&#13;
&#13;
<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
}
?>
&#13;
&#13;
&#13;

我读到可以使用$ _GET,因为它会在网址中保存信息?!

2 个答案:

答案 0 :(得分:0)

检查一下,

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

这应该是howbutton

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

答案 1 :(得分:0)

您的提交按钮没有name,这会导致您的if (isset($_POST['submit']))错误。您还试图echo来自错误元素名称的数据,它应该是$_POST['howbutton']尝试以下代码:

<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" name="submit" class="btn" type="submit" value="get trial"/></span>
</form>

<?php
if (isset($_POST['submit'])) {

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