【发布时间】:2014-01-07 12:07:33
【问题描述】:
我为这项工作制作了一个普通表格,供用户以表格形式提交数据名称、电子邮件和城市,我使用了一些编码,但我仍然不知道我在哪里弄错了请提出建议。
路线
$route['default_controller'] = "welcome";
控制器中的welcome.php
public function index()
{
$this->load->view('ar_signup');
$this->load->helper('url');
}
}
视图中表单的 ar_signup
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Landing Page</title>
<meta charset="utf-8">
<link href="assests/css/ar/ar.css" rel="stylesheet" type="text/css">
</head>
<body>
<?php echo validation_errors(); ?>
<?php echo form_open('user'); ?>
<label for="name">Name:</label>
<input type="name" id="name" name="name">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<label for="city">City:</label>
<input type="city" id="city" name="city">
<input type="submit" value="Login">
</div>
</form>
</body>
</html>
控制器中的user.php
<?php
function create_member()
{
$this->load->library('form_validation');
// field name, error message, validation rules
$this->form_validation->set_rules('name', 'Name', 'trim|required');
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules('city', 'City', 'trim|required');
if($this->form_validation->run() == FALSE)
{
$this->load->view('ar_thanks');
}
else
{
$this->load->model('users_model');
if($query = $this->Users_model->create_member())
{
$this->load->view('ar_landing');
}
}
}
模型中提到的user_model.php
<?php
function create_member()
{
$this->db->where('user_name', $this->input->post('username'));
$query = $this->db->get('users');
if($query->num_rows > 0){
}else{
$new_member_insert_data = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'city' => $this->input->post('city'),
);
$insert = $this->db->insert('users', $new_member_insert_data);
return $insert;
}
}//create_member
}
【问题讨论】:
-
有什么问题?你有什么错误吗?
-
你的
$this->load->helper('form');在哪里? -
在自动加载中我添加 $autoload['helpers'] = array('form');
-
那么问题出在哪里?
-
当我提交表单时显示,未找到在此服务器上未找到请求的 URL /landingpage/user。
标签: php forms codeigniter