view下的代码应该写成:
<?php
$attributes = array('name' => 'testform');
echo form_open('home/valid/',$attributes); //home 是一个controller的名字,你根据你的程序修改
?>
<input type="text" name="idno" id="idno" value="<?php echo set_value('idno'); ?>" size="20" maxlength="30" />
<div id="mes_erreur"><?php echo form_error('idno');?></div> 这里是为了显示错误信息的
</p>
<p>
<label>
<input type="submit" name="send" id="send" value="Envoyer" />
</label>
</form>
</p>
Controller下的代码:
$this->load->helper('form'); $this->load->library('form_validation');
这两行你加在适当的位置
function valid() { $this->form_validation->set_rules('idno', 'Idno', 'required|callback_idno_check'); if ($this->form_validation->run() == FALSE) { $this->load->view('form'); } else { $this->load->view('formsuccess'); }
} function idno_check($str){ if($str == '123'){ $this->form_validation->set_message('idno_check', 'The %s field can not be the word "123"'); return false; }else{ return true; }
}
|