在控制器处接收后变量。
查看:loginhome.php
<?php
//-----------------------------------------------------------------------------
// Including Header
//-----------------------------------------------------------------------------
$base = dirname(__FILE__);
include($base . '/header.php');
?>
<div class="login-wrap">
<div class="login-html">
<input id="tab-1" type="radio" name="tab" class="sign-in" checked><label for="tab-1" class="tab">Sign In</label>
<input id="tab-2" type="radio" name="tab" class="sign-up"><label for="tab-2" class="tab">Sign Up</label>
<div class="login-form">
<div class="sign-in-htm">
<?php
$attributes = array(
'name' => 'login_form',
'id' => 'login_form',
'method' => 'POST'
);
echo form_open('VerifyLogin', $attributes);
?>
<div class="group">
<label for="user" class="label">Username</label>
<?php
$data = array(
'name' => 'user',
'id' => 'user',
'class' => 'input'
);
echo form_input($data);
?>
</div>
<div class="group">
<label for="pass" class="label">Password</label>
<?php
$data = array(
'name' => 'pass',
'id' => 'pass',
'class' => 'input'
);
echo form_password($data);
?>
</div>
<div class="group">
<input id="check" type="checkbox" class="check" checked>
<label for="check"><span class="icon"></span> Keep me Signed in here</label>
</div>
<div class="group">
<?php
$data = array(
'name' => 'SignIn',
'id' => 'SignIn',
'value' => 'Sign In',
'class' => 'button'
);
echo form_submit($data);
//echo anchor('forgotpassword', 'Forgot Password???', 'class="link-class"');
?>
</div>
<?php
echo form_close();
?>
<div class="hr"></div>
<div class="foot-lnk">
<a href="#forgot">Forgot Password?</a>
</div>
</div>
<?php
$attributes = array(
'name' => 'sign-up_form',
'id' => 'sign-up_form',
'method' => 'GET'
);
echo form_open('RegisterUser', $attributes);
?>
<div class="sign-up-htm">
<div class="group">
<label for="user" class="label">Name</label>
<?php
$data = array(
'id' => 'name',
'type' => 'text',
'class' => 'input'
);
echo form_input($data);
?>
</div>
<div class="group">
<label for="user" class="label">Username</label>
<?php
$data = array(
'id' => 'username',
'type' => 'text',
'class' => 'input'
);
echo form_input($data);
?>
</div>
<div class="group">
<label for="pass" class="label">Password</label>
<?php
$data = array(
'id' => 'password',
'type' => 'password',
'class' => 'input'
);
echo form_password($data);
?>
</div>
<div class="group">
<label for="pass" class="label">Repeat Password</label>
<?php
$data = array(
'id' => 'password',
'type' => 'password',
'class' => 'input'
);
echo form_password($data);
?>
</div>
<div class="group">
<label for="pass" class="label">Email Address</label>
<?php
$data = array(
'id' => 'email',
'type' => 'text',
'class' => 'input'
);
echo form_input($data);
?></div>
<div class="group">
<?php
$data = array(
'id' => 'submitButton',
'type' => 'submit',
'value' => 'request',
'class' => 'button'
);
echo form_submit($data);
//echo form_close();
?>
</div>
<div class="hr"></div>
<div class="foot-lnk">
<label for="tab-1"><a href='#Already'>Already Member?</a></label>
</div>
</div>
<?php
echo form_close();
?>
</div>
</div>
<?php
//-----------------------------------------------------------------------------
// Including Footer
//-----------------------------------------------------------------------------
$base = dirname(__FILE__);
include($base . '/footer.php');
?>
Controller:RegisterUser.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class RegisterUser extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('InsertUser','',TRUE);
}
function index()
{
echo 'Hello World123';
//This method will have the credentials validation
$this->load->library('form_validation');
$name = $this->input->post('name');
$username = $this->input->post('username');
$password = $this->input->post('password');
$email = $this->input->post('email');
echo 'User name: '.$username.'Password: '.$password;
/*
$this->form_validation->set_rules('name', 'Name', 'required');
$this->form_validation->set_rules('username', 'User Name', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_rules('email', 'E-Mail', 'required');
//$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
if($this->form_validation->run() == FALSE)
{
//Field validation failed. User redirected to login page
echo 'Something is not in format';
$this->load->view('loginhome');
}
else
{
//Go to private area
$this->insert_database();
redirect('home', 'refresh');
}*/
//$this->insert_database();
echo 'This is it';
}
function insert_database()
{
//Field validation succeeded. Validate against database
$name = $this->input->post('name');
$username = $this->input->post('username');
$password = $this->input->post('password');
$email = $this->input->post('email');
echo $username.$password;
//query the database
$result = $this->InsertUser->form_insert($name,$username, $password,$email);
echo 'Inserted';
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array(
'id' => $row->user_id,
'username' => $row->user_name
);
$this->session->set_userdata('logged_in', $sess_array);
echo 'logged-in';
}
return TRUE;
}
else
{
$this->form_validation->set_message('check_database', 'Invalid username or password');
echo 'log-in failed';
return false;
}
}
}
?>
即使您将Post更改为get,也不会更改http请求查询。
登录模块工作正常,但注册无效。
答案 0 :(得分:3)
将方法GET
更改为POST
<?php
$attributes = array(
'name' => 'sign-up_form',
'id' => 'sign-up_form',
'method' => 'POST'
);
和
Foreach你的字段添加name
这样的属性..
$data = array(
'name'=>'name',
'id' => 'name',
'type' => 'text',
'class' => 'input'
);
和
$data = array(
'name' => 'username'
'id' => 'username',
'type' => 'text',
'class' => 'input'
);
so on...
用于注册表单。
然后,您可以使用name
$this->input->post('name');
获取字段