我在login.php控制器中创建了一个简单的process_login函数。法典:
<?php
Class Login extends Controller {
var $title = 'Login';
function __construct() {
parent::__construct();
$this->load->model('Login_Model');
}
function index() {
$profile['_profile'] = $this->xProfile_Model->GetProfile();
$this->load->view('login', array('title' => $this->title, '_profile' => $profile['_profile']));
}
function process_form() {
$ret['command'] = "login process";
if($this->input->post('username') == 'admin' && md5($this->input->post('pwd')) == 'e6d8b61d43b5a1c5e4727e92351681f6') {
//EMERGENCY ONLY
$data['id'] = '1';
$data['name'] = 'admin';
$data['group_id'] = '1';
$this->session->set_userdata($data);
$ret['msg'] = $this->lang->line('msg_success') . ', ' . $this->lang->line('msg_please_wait');
$ret['status'] = "success";
}
和登录视图:
<form method="post" id="signin" action="<?php echo site_url('login/process_form')?>">
<label for="username">Username</label>
<input id="username" name="username" value="" class="required" tabindex="4" type="text" onkeypress="focusNext('pwd', 'login', this, event)" />
</p>
<p>
<label for="password">Password</label>
<input id="pwd" name="pwd" value="" class="required" tabindex="5" type="password">
</p>
<p class="clear"></p>
<a href="#" class="forgot" style="display:none;" id="resend_password_link">Lupa password?</a>
<p class="remember">
<input id="signin_submit" value="Login" tabindex="6" type="submit"/>
<input id="cancel_submit" value="Batal" tabindex="7" type="button"/>
<input id="batal" value="TES" tabindex="7" type="button" onclick="<?php site_url('login/tes')?>"/>
</p>
</form>
当我按下登录按钮时,那里什么也没发生。这段代码可能有什么问题?
我正在尝试表单操作以:
site_url('login/process_form'),site_url('login.php/process_form'),base_url;('process_form')
但它仍然不起作用!
请帮助我,谢谢。
您没有在process_form
函数中加载视图,也没有重定向到实际加载内容的页面。
此外,如果不满足 if 语句的条件,它现在的编写方式不应该做任何事情,实际上函数并没有关闭。
最后,HTML 中存在错误
- 没有
HTML 输入类型的按钮,它的正确语法是
<button id="batal" tabindex="7">TES</button>
此外,OnClick 不正确,这可能是您的表单未提交的原因。 现在,它只会呈现为您需要提交表单onclick="someurl..."
。