使用php验证单选按钮

时间:2014-11-12 12:59:09

标签: php html codeigniter

我目前正在使用CodeIgniter作为我的网页,如果locked_status被锁定,我正在尝试选择单选按钮,反之亦然。我有传递给视图的数据,我想使用数据来检查locked_status是否被锁定。用户可以更改locked_status,并在提交表单时,在提交表单时相应地更新数据。我试图使用javascript,但我不知道如何检索数据并检查它。或者还有其他更好的方法吗?

我的控制器加载视图并将数据传递给视图。

function userInformation($userName)
    {                           
        $this->load->model("agentDB_model");

        $data['results'] = $this->agentDB_model->getSelectedAgentDetails($userName);

        $this->load->view("viewAgentInfo_view", $data);     

    }

视图

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Welcome</title>
</head>
<body>

    <div id="content">
        <h1>Home Page</h1>
        <p>Selected Agent Information</p>
    </div>  


    <?php
    foreach($results as $row)
    {
        $userName = $row->userName;
        $userPassword = $row->userPassword;
        $agencyName = $row->agencyName;
        $agencyCodeNo = $row->agencyCodeNo;
        $invalidLoginCount = $row->invalidLoginCount;
        $locked_status = $row->locked_status;
        $logged_in = $row->logged_in;
    }
    /*
    if($row->locked_status == 0)
    {
        $locked_status = "Avalaible";
    }
    else if($row->locked_status == 1)
    {
        $locked_status = "Locked";
    }

     */
    ?>

    <?php echo form_open('site/updateValues') ?>
            User Name: <input type="text" name="tbx_userName" value="<?php echo "$userName"?>" readonly/></br>
            User Password: <input type="password" name="tbx_userPassword" value="<?php echo "$userPassword"?>"/></br>   
            Agency Name: <input type="text" name="tbx_agencyName" value="<?php echo "$agencyName"?>"/></br> 
            Agency Code Number: <input type="text" name="tbx_agencyCodeNo" value="<?php echo "$agencyCodeNo"?>"/></br>
            Invalid Login Count: <input type="text" readonly name="tbx_invalidLoginCount" value="<?php echo "$invalidLoginCount"?>"/></br>
            Locked Status: <input type="radio" name="locked_status" id="lock">Lock
            <input type="radio" name="locked_status" id="unlock">Unlock
            <br/>
            <!--<input name="tbx_locked_status" value="<?php echo "$locked_status"?>" readonly/></br> -->
            Logged In: <input type="text" readonly name="tbx_logged_in" value="<?php echo "$logged_in"?>" /></br>

            <input type="submit" value="Submit"/>           
    </form>


    <div id="footer">
        <p>Copyright (c) 2012 basicsite.com</p>
    </div>


</body>
</html>

1 个答案:

答案 0 :(得分:0)

试试这个

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Welcome</title>
</head>
<body>

    <div id="content">
        <h1>Home Page</h1>
        <p>Selected Agent Information</p>
    </div>  


    <?php
    foreach($results as $row)
    {
        $userName = $row->userName;
        $userPassword = $row->userPassword;
        $agencyName = $row->agencyName;
        $agencyCodeNo = $row->agencyCodeNo;
        $invalidLoginCount = $row->invalidLoginCount;
        $locked_status = $row->locked_status;
        $logged_in = $row->logged_in;

  if($row->locked_status == 0)
    {
        $locked_status = "<input type="radio" name="locked_status" checked value=0 id="lock">Locked <input type="radio" name="locked_status" id="unlock" value=1> Unlocked";
    }
    else if($row->locked_status == 1)
    {
        $locked_status = "  <input type="radio" name="locked_status" value=0 id="lock"> Locked <input type="radio" name="locked_status" checked  id="unlock" value=1> Unloacked";
    }


  }



    ?>

    <?php echo form_open('site/updateValues') ?>
            User Name: <input type="text" name="tbx_userName" value="<?php echo "$userName"?>" readonly/></br>
            User Password: <input type="password" name="tbx_userPassword" value="<?php echo "$userPassword"?>"/></br>   
            Agency Name: <input type="text" name="tbx_agencyName" value="<?php echo "$agencyName"?>"/></br> 
            Agency Code Number: <input type="text" name="tbx_agencyCodeNo" value="<?php echo "$agencyCodeNo"?>"/></br>
            Invalid Login Count: <input type="text" readonly name="tbx_invalidLoginCount" value="<?php echo "$invalidLoginCount"?>"/></br>
            Locked Status: <?php echo $locked_status; ?>
            <br/>

            Logged In: <input type="text" readonly name="tbx_logged_in" value="<?php echo "$logged_in"?>" /></br>

            <input type="submit" value="Submit"/>           
    </form>


    <div id="footer">
        <p>Copyright (c) 2012 basicsite.com</p>
    </div>


</body>
</html>