表单不是从单选按钮获取值

时间:2014-01-02 12:49:45

标签: php jquery html css twitter-bootstrap

使用bootstrap 3

的Html表单
<form action="valuecheck.php" onsubmit="return passcheck();" method="POST" id="signup-form">
    <div class="form-group">
        <label>Email address</label>
        <input class="form-control" type="email" name="email" placeholder="Enter email address" value="" required/>
    </div>
    <div class="form-group">
        <label>Password</label>
        <input class="form-control" type="password" name="password1" placeholder="Enter Password" required/>
    </div>
    <div class="form-group">
        <label>Re-enter password</label>
        <input class="form-control" type="password" name="password2" placeholder="Re-enter Password" required/>
    </div>
    <div class="form-group">
        <label>Area of Education / Working</label>
        <select class="form-control" name="area" required>
            <optgroup label="Other Disciplines">
                <option value='Architect'>Architect</option>
                <option value='Journalism'>Journalism</option>
                <option value='Law'>Law</option>
                <option value='Management'>Management</option>
                <option value='Medical'>Medical</option>
                <option value='other'>other</option>
            </optgroup>
        </select>
    </div>
    <div class="form-group">
        <label class="radio-inline">
            <input type="radio" name="sex" value="male" required>Male</label>
        <label class="radio-inline">
            <input type="radio" name="sex" value="female" required>Female</label>
    </div>
    <button type="submit" class="btn btn-primary">Sign Up</button>
</form>

php文件

<?php if(isset($_POST[ 'email'])&isset($_POST[ 'password1'])&isset($_POST[ 'password2'])&isset($_POST[ 'area'])&isset($_POST[ 'sex'])){ print_r($_POST); } ?>

结果

Array ( [email] => uhiwarale@gmail.com [password1] => 1 [password2] => 1 [area] => Process Engineering [sex] => )

问题

看起来表格没有从收音机盒中获取价值。我删除了表单组和无线电内联类,但它仍然没有获取值。任何人都可以解决这个问题吗?

2 个答案:

答案 0 :(得分:4)

尝试改变这一点:

$_POST[ 'sex1']

到此:

$_POST[ 'sex']

您正在发布的字符串中发送sex,并且您正在使用sex1访问该字符串,但不匹配,因此问题就在这里。

并且你发布了你的php代码,因为单& &&应该有<?php if(isset($_POST[ 'email'])&& isset($_POST[ 'password1'])&& isset($_POST[ 'password2'])&& isset($_POST[ 'area'])&& isset($_POST[ 'sex'])){ //<------change here to 'sex' print_r($_POST); } ?> ,这似乎不正确:

{{1}}

答案 1 :(得分:0)

当单选按钮名称为sex1

时,您尝试获取sex