dsxgby126001 2014-11-07 07:12
浏览 50
已采纳

表单提交返回空数据

I'm using PHP Framework CodeIgniter.

View

<?php echo form_open('login/connect'); ?>
    <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td><?php echo form_label('Username', 'username'); ?></td>
            <td><?php echo form_input(array('id'=>'username', 'name'=>'username')); ?></td>
        </tr>
        <tr>
            <td><?php echo form_label('Password', 'password'); ?></td>
            <td><?php echo form_password(array('id'=>'password', 'name'=>'password')); ?></td>
        </tr>
        <tr>
            <td></td>
            <td><?php echo form_submit('login_submit', 'Valider'); ?></td>
        </tr>
    </table>
<?php echo form_close(); ?>

When I try to submit this page it goes to: http://mywebsite.com/admin/index.php/login/connect

Controller

class Login extends CI_Controller {

function __construct()
{
    parent::__construct();
}

function index()
{
    $this->load->view('login');
}

function connect()
{
    $username= $this->input->post('username');
    $password=$this->input->post('password');
    echo $username.', '.$password;
}

}

HTML

<div id="login">
    <div id="login-inner">
        <h1>Login</h1>
        <form action="http://myswebsite.com/admin/index.php/login/connect" method="post" accept-charset="utf-8">                    
            <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <td><label for="username">Username</label></td>
                    <td><input type="text" name="username" value="" id="username"  /></td>
                </tr>
                <tr>
                    <td><label for="password">Password</label></td>
                    <td><input type="password" name="password" value="" id="password"  /></td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="submit" name="login_submit" value="Valider"  /></td>
                </tr>
            </table>
        </form>
    </div>
</div>

But it returns an empty array.

Can anyone suggest a method to fix this?

Thanks.

  • 写回答

4条回答 默认 最新

  • duanliang9288 2014-11-07 07:48
    关注

    Identified the issue. It was related to the website url, and there was an unwanted 301 redirect when the form submits. Reference: $this->input->post() always returning FALSE, due to an unwanted 301

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度