Welcome Guest, Not a member yet? Register   Sign In
File Uploading
#11

[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

&lt;html&gt;
&lt;head&gt;&lt;title>JS Validation&lt;/title&gt;
&lt;!--[removed][removed]--&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php echo form_open('test/add'); ?&gt;
&lt;!--&lt;form id="frmJsValidation" action="&lt;?php //echo base_url() ?&gt;test/add" method="post"&gt;--&gt;
<table>
<tr>
<td colspan="2">
<div id="msg">
</div>
</td>

</tr>
<tr>
<td colspan="2">
&lt;?php echo validation_errors(); ?&gt;
&lt;?php echo form_error('name_check'); ?&gt;
</td>
</tr>
<tr>
<td>Name</td>
<td>&lt;input type="text" id="name" name="name" value="&lt;?php echo set_value('name'); ?&gt;" /&gt;&lt;?php //echo form_error('name')?&gt;</td>
</tr>
<tr>
<td>Address</td>
<td>&lt;input type="text" id="address" name="address" value="&lt;?php echo set_value('address'); ?&gt;" /&gt;&lt;?php //echo form_error('address')?&gt;</td>
</tr>
<tr>
<td>Email</td>
<td>&lt;input type="text" id="email" name="email" value="&lt;?php echo set_value('email'); ?&gt;" /&gt;&lt;?php //echo form_error('email')?&gt;</td>
</tr>
<tr>
<td>&lt;input type="button" value="Click"&gt;&lt;/td>
<td>&lt;input type="submit" id="btn" value="Submit" /&gt;&lt;/td>
</tr>
</table>
&lt;!--&lt;/form&gt;--&gt;
&lt;?php form_close(); ?&gt;
&lt;/body&gt;
&lt;/html&gt;


But call back function is not workig...I tried to many ways. please help me again....................
#12

[eluser]Achintha Madushan[/eluser]
Ok........problem is ok now.

function add()
{
//set validation rules
$this->form_validation->set_rules('name', 'Name', 'required|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;
}

I put call back function out side of add method... now it ok... thanks for alllllll Big Grin
#13

[eluser]Achintha Madushan[/eluser]
I have antother problem.

&lt;input type = "checkbox" name = "mod1" value = "1" /&gt;
&lt;input type = "checkbox" name = "mod1" value = "5" /&gt;
&lt;input type = "checkbox" name = "mod1" value = "2" /&gt;
&lt;input type = "checkbox" name = "mod1" value = "3" /&gt;
&lt;input type = "checkbox" name = "mod1" value = "4" /&gt;

I want to get checked values in controller via PHP ... Please help me........

Dont tell me use name and id as mod1[]




Theme © iAndrew 2016 - Forum software by © MyBB