【问题标题】:Grab post info from radio button in Vbulletin从 Vbulletin 中的单选按钮获取帖子信息
【发布时间】:2012-03-12 07:09:40
【问题描述】:
<tr>
  <td valign="top">
    <label for="rb_cpf_field6_1">
      Seller: I would like to list my equipment 
    </label>
    <input type="radio" name="userfield[field6]" value="1" id="rb_cpf_field6_1" checked="checked" />
  </td>
</tr>
<tr>
  <td valign="top">
    <label for="rb_cpf_field6_2">
      Buyer: I'd like to inquire about a listing
    </label>
    <input type="radio" name="userfield[field6]" value="2" id="rb_cpf_field6_2"  />
  </td>
</tr>
<tr>
  <td valign="top">
    <label for="rb_cpf_field6_3">
      Both: I'm interested in buying and selling
    </label>
    <input type="radio" name="userfield[field6]" value="3" id="rb_cpf_field6_3"  />
  </td>
</tr>
<tr>
  <td valign="top">
    <label for="rb_cpf_field6_4">
      Other: I'm here for another purpose
    </label>
    <input type="radio" name="userfield[field6]" value="4" id="rb_cpf_field6_4"  />
  </td>
</tr>

我需要能够从这些单选按钮选择中获取帖子信息(在 PHP 中),所以我可以这样做:

如果(is_a_buyer){ 做这个 } 别的 { 做别的事 }

任何帮助将不胜感激!

【问题讨论】:

    标签: php forms button radio


    【解决方案1】:

    检查$_POST 全局变量。 看看当你这样做时会发生什么:

    var_dump($_POST);
    

    选中的单选按钮的值应该是$_POST['userfield[field6]']

    【讨论】:

      【解决方案2】:
      <form name="something" action="check.php" method="POST">
      <tr>
          <td valign="top">
              <label for="rb_cpf_field6_1">
                  Seller: I would like to list my equipment 
              </label>
              <input type="radio" name="userfield[field6]" value="1" id="rb_cpf_field6_1" checked="checked" />
          </td>
      </tr><tr>
          <td valign="top">
              <label for="rb_cpf_field6_2">
                  Buyer: I'd like to inquire about a listing
              </label>
              <input type="radio" name="userfield[field6]" value="2" id="rb_cpf_field6_2"  />
          </td>
      </tr><tr>
          <td valign="top">
              <label for="rb_cpf_field6_3">
                  Both: I'm interested in buying and selling
              </label>
              <input type="radio" name="userfield[field6]" value="3" id="rb_cpf_field6_3"  />
        </td>
      </tr><tr>
          <td valign="top">
              <label for="rb_cpf_field6_4">
                  Other: I'm here for another purpose
              </label>
          <input type="radio" name="userfield[field6]" value="4" id="rb_cpf_field6_4"  />
        </td>
      </tr>
      </form>
      

      这是您的主要代码(我添加了表单标签,认为它不存在。如果存在,请删除它们。)

      现在,在check.php 页面上,使用这个:

      if ($_POST['userfield[field6]'] == 2 || $_POST['userfield[field6]'] == 3) {
          do this;
      }
      else {
          do something else;
      }
      

      【讨论】:

        【解决方案3】:
        if (isset($_POST['insertRadioButtonName']) == radioButtonValue || isset($_POST['insertOtherRadioButtonName']) == otherRadioButtonValue) {
            echo 'idk';
        } else {
            echo 'something';
        }
        

        【讨论】:

          猜你喜欢
          • 2015-04-25
          • 2011-03-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-03-12
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多