[eluser]Achintha Madushan[/eluser]
This is my add function in controller
function add()
{
//set validation rules
$this->form_validation->set_rules('name', 'Name', 'callback__name_check');
$this->form_validation->set_rules('address', 'Address', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_message('name_check', 'The %s field cannot be <strong>Achintha</strong>');
if ($this->form_validation->run()==FALSE)
{
$this->load->view('jsValidation');
}else {echo "Success";}
function _name_check($str) {//exit;//return FALSE;
if ($str == 'Achintha')
return FALSE;
else
return TRUE;
}
}
And this is my view
<html>
<head><title>JS Validation</title>
<!--[removed][removed]-->
</head>
<body>
<?php echo form_open('test/add'); ?>
<!--<form id="frmJsValidation" action="<?php //echo base_url() ?>test/add" method="post">-->
<table>
<tr>
<td colspan="2">
<div id="msg">
</div>
</td>
</tr>
<tr>
<td colspan="2">
<?php echo validation_errors(); ?>
<?php echo form_error('name_check'); ?>
</td>
</tr>
<tr>
<td>Name</td>
<td><input type="text" id="name" name="name" value="<?php echo set_value('name'); ?>" /><?php //echo form_error('name')?></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" id="address" name="address" value="<?php echo set_value('address'); ?>" /><?php //echo form_error('address')?></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" id="email" name="email" value="<?php echo set_value('email'); ?>" /><?php //echo form_error('email')?></td>
</tr>
<tr>
<td><input type="button" value="Click"></td>
<td><input type="submit" id="btn" value="Submit" /></td>
</tr>
</table>
<!--</form>-->
<?php form_close(); ?>
</body>
</html>
But call back function is not workig...I tried to many ways. please help me again....................