[eluser]fuji2009[/eluser]
Hi i have a problem with callback function :
Code: function check_infos()
{
extract($_POST);
if (!empty($info))
{
$this->db->select('*');
$this->db->from('loris');
$this->db->where('email', $info);
$this->db->where('user1_id', $user_login_id);
$this->db->where('user2_id', $user_id);
$query = $this->db->get();
if($query->num_rows() > 0)
{
$this->form_validation->set_message('check_infos', 'Already exist');
return false;
}
else
{
return true;
}
}
}
Request :
SELECT * FROM (`loris`) WHERE `email` = ' [email protected]' AND `user1_id` = '2' AND `user2_id` = '5'
The request is good but, the callback dont work
Can you help me ?
in my controller i have this :
Code: $this->form_validation->set_rules('info','info','callback_check_infos|trim|required|xss_clean');
if ($this->form_validation->run())
{
.......................................
}
Thanks you
[eluser]Cristian Gilè[/eluser]
Code: function check_infos($str)
{
$this->db->select('*');
$this->db->from('loris');
$this->db->where('email', $str);
$this->db->where('user1_id', $user_login_id);
$this->db->where('user2_id', $user_id);
$query = $this->db->get();
if($query->num_rows() > 0)
{
$this->form_validation->set_message('check_infos', '%s already exist');
return false;
}
else
{
return true;
}
}
Code: $this->form_validation->set_rules('info','info','trim|required|valid_email|callback_check_infos|xss_clean');
if ($this->form_validation->run() == FALSE)
{
//reload the view
}
else
{
//success page
}
Cristian Gilè
[eluser]fuji2009[/eluser]
I do it but don t work, just the form false run and load the view page but, the error message is not here.
For exemple , i try , put nothing in the form and validate and it s load a new page, normally he must say : this input is required ...
What s the problem ?
Thanks you
[eluser]Cristian Gilè[/eluser]
Have you put in your view echo validation_errors(); ?
Please, post your controller and view code.
Cristian Gilè
[eluser]fuji2009[/eluser]
my view :
Code: <div id="ploran" title="i">
<?php echo form_open('profile/pre_loran/'.$user_id,'name="loran"');?>
<table width="400px">
<tr>
<td><?php if ($photos == false): ?>
<img width="65px" height="65px;" src="../../../users/Default/Hfdrtgrdegdf1.gif"/>
<?php else: ?>
<img width="65px" height="65px;"src="<?php echo $photos[0]['thumbs'];?>"/>
<?php endif;?>
</td>
</tr>
<tr>
<td><input type="text" name="info" id="info" size="20" value="" /></td>
<input type="hidden" name="user_login_id" value="<?php echo $user_login_id;?>">
<input type="hidden" name="user_id" value="<?php echo $user_id;?>">
<input type="hidden" name="photos" value="<?php echo $photos[0]['thumbs'];?>">
</tr>
<tr><td><?php echo form_error('info','<div class="error">','</div>');?></td></tr>
<tr>
<td><?php echo form_submit('valid_loran','Valider');?></td>
</tr>
<?php echo form_close();?>
</table>
</div>
and my controller
Code: function pre_loran($user_id){
$data['page'] = 'person_error';
$data['title'] = 'Erreur';
$data['username'] = $this->session->userdata('username');
$data['user_id'] = '';
$data['user2_id'] = '';
$this->load->model('profile_model');
$this->form_validation->set_rules('info','Info','callback_check_infos|trim|required|valid_email|xss_clean');
if ($this->form_validation->run())
{
$data['page'] = 'person_success';
$data['title'] = 'pre loran';
extract($_POST);
$username = $this->profile_model->get_username_by_id($user_login_id);
$username_profil=$this->profile_model->get_username_by_id($user_id);
$email_profil=$this->profile_model->get_email($user_id);
$this->email->from('[email protected]', 'Presn');
$this->email->to($email_profil);
$this->email->subject('pre_loran');
$this->email->message(''.$username.' <img src="'.$photos.'" />
<a href="#">Click</a>
');
$this->email->send();
$pre_loran = array(
'user1_id' => $user_login_id,
'user2_id' => $user_id,
'user3_id' => '',
'email' => $info,
'type' => 'present',
'valide' => 0,
'created_at' => date('Y-m-d h:i:s',now())
);
$this->profile_model->pre_loran($pre_loran);
$data['demande'] = 'Mee';
}
$data['die']='Already do this action';
$this->load->view('layout/application', $data);
}
function check_infos($str)
{
extract($_POST);
$this->db->select('*');
$this->db->from('meeting');
$this->db->where('email', $str);
$this->db->where('user1_id', $user_login_id);
$this->db->where('user2_id', $user_id);
$query = $this->db->get();
if($query->num_rows() > 0)
{
$this->form_validation->set_message('check_infos', 'Already do');
return false;
}
else
{
return true;
}
}
thanks for your help
[eluser]InsiteFX[/eluser]
The call back needs to be in the controller with you other form code or it will not work!
InsiteFX
[eluser]fuji2009[/eluser]
Hum i not understand the callback is in the controller function check_infos
[eluser]Cristian Gilè[/eluser]
Remove some code from the if statement in the pre_loran function as follow:
Code: $this->form_validation->set_rules('info','Info','trim|required|valid_email|callback_check_infos|xss_clean');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('your_view_name'); //reload the view to show errors
}
else
{
redirect('controller/method'); //redirect to the success page
}
and check if it works.
Cristian Gilè
|