Codeigniter单选按钮回调验证错误?
如果使用Codeigniter回调验证错误未选择性别,我想显示错误消息 我的HTML页面Codeigniter单选按钮回调验证错误?,codeigniter,Codeigniter,如果使用Codeigniter回调验证错误未选择性别,我想显示错误消息 我的HTML页面 我试了很多次。。。请帮助……尝试使用$this->input->post('gender')而不是$str <?php class Welcome extends CI_Controller { public function __construct() { parent::__construct(); $this->load->library('form_va
我试了很多次。。。请帮助……尝试使用
$this->input->post('gender')
而不是$str
<?php
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
}
public function index() {
$this->form_validation->set_rules('gender', 'Gender', 'callback_gender');
if ($this->form_validation->run() == FALSE) {
// Load view
} else {
// Success Stuff
}
}
public function gender() {
if ($this->input->post('gender')) {
return TRUE;
} else {
$this->form_validation->set_message( 'gender', 'Please Choose gender' );
return FALSE;
}
}
}
尝试使用
$this->input->post('gender')
而不是$str
<?php
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
}
public function index() {
$this->form_validation->set_rules('gender', 'Gender', 'callback_gender');
if ($this->form_validation->run() == FALSE) {
// Load view
} else {
// Success Stuff
}
}
public function gender() {
if ($this->input->post('gender')) {
return TRUE;
} else {
$this->form_validation->set_message( 'gender', 'Please Choose gender' );
return FALSE;
}
}
}
@罗伯特威利斯:你有表格吗?你的问题没有太多细节,先生,它起作用了。。。我遵循了你的答案,它也起作用了。。。谢谢…@RobertWillis你有表格吗?你的问题没有太多细节,先生,它起作用了。。。我遵循了你的答案,它也起作用了。。。谢谢
<?php
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
}
public function index() {
$this->form_validation->set_rules('gender', 'Gender', 'callback_gender');
if ($this->form_validation->run() == FALSE) {
// Load view
} else {
// Success Stuff
}
}
public function gender() {
if ($this->input->post('gender')) {
return TRUE;
} else {
$this->form_validation->set_message( 'gender', 'Please Choose gender' );
return FALSE;
}
}
}
<?php
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('form_validation');
}
public function index() {
$this->form_validation->set_rules('gender', 'Gender', 'callback_gender[gender]');
if ($this->form_validation->run() == FALSE) {
// Load view
} else {
// Success Stuff
}
}
public function gender($str) {
if ($str == '') {
$this->form_validation->set_message( 'gender', 'Please Choose gender' );
return FALSE;
} else {
return TRUE;
}
}
}