我正在尝试在我的表单中加载错误消息,但是现在它加载我的表单页面4次,有人知道我做错了什么?我只想要负载:
$ adb shell ps | grep system_server
system 731 441 1094884 89232 ffffffff b74d1d05 S system_server
$
控制器:
<span class="text-danger">
user_view.php
<?php
/*
* File Name: user.php
*/
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
$this->load->database();
$this->load->library('form_validation');
//load the user model
$this->load->model('User_model');
}
//index function
function index()
{
//fetch data from country table
$data['country'] = $this->User_model->get_country();
//set validation rules
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
$this->form_validation->set_rules ('passconf', 'Password Confirmation', 'trim|required');
if ($this->form_validation->run() == FALSE)
{
//fail validation
$this->load->view('user_view2', $data);
}
else
{
//pass validation
$data = array(
'user_email' => $this->input->post('email'),
'Password' => $this->input->post('passconf'),
//encrypting pass on database.
'Password' => password_hash('passconf', PASSWORD_BCRYPT),
);
//insert the form data into database
$this->db->insert('test', $data);
//display success message
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">You Are Now Registered</div>');
redirect('user/index');
}
}
//custom validation function for dropdown input
function combo_check($str)
{
if ($str == '-SELECT-')
{
$this->form_validation->set_message('combo_check', 'Invalid %s you need pick one');
return FALSE;
}
else
{
return TRUE;
}
}
//custom validation function to accept only alpha and space input
function alpha_only_space($str)
{
if (!preg_match("/^([-a-z ])+$/i", $str))
{
$this->form_validation->set_message('alpha_only_space', 'The %s field must contain only alphabets or spaces');
return FALSE;
}
else
{
return TRUE;
}
}
}
?>
jquery代码
<?php
$attributes = array("class" => "form-horizontal", "id" => "userform", "name" => "userform");
echo form_open("user/index", $attributes);?>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="email" class="control-label">Email address</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="email" name="email" placeholder="type your email here" type="text" class="form-control" value="<?php echo set_value('email'); ?>" />
<span class="text-danger"><?php echo form_error('email'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="passconf" class="control-label">Password</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="passconf" name="passconf" placeholder="your password" type="password" class="form-control" value="<?php echo set_value('passconf'); ?>" />
<span class="text-danger"><?php echo form_error('passconf'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-lg-8 col-sm-8 text-left">
<input id="btn_add" name="btn_add" type="submit" class="btn btn-primary" value="Insert" />
<input id="btn_cancel" name="btn_cancel" type="reset" class="btn btn-danger" value="Cancel" />
</div>
</div>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
答案 0 :(得分:-1)
frm.submit
会将表单发回服务器,如果您不希望将表单发回给return false;
,则需要在ev.preventDefault();
之后添加RedisObjectConstructor.create
服务器