Welcome Guest, Not a member yet? Register   Sign In
callback problem
#1

[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
#2

[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è
#3

[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
#4

[eluser]Cristian Gilè[/eluser]
Have you put in your view echo validation_errors(); ?

Please, post your controller and view code.


Cristian Gilè
#5

[eluser]fuji2009[/eluser]
my view :

Code:
<div id="ploran" title="i">
    &lt;?php echo form_open('profile/pre_loran/'.$user_id,'name="loran"');?&gt;
            <table width="400px">
                <tr>
                    
                    <td>&lt;?php if ($photos == false): ?&gt;
                        <img width="65px" height="65px;" src="../../../users/Default/Hfdrtgrdegdf1.gif"/>
                        &lt;?php else: ?&gt;
                        <img width="65px" height="65px;"src="&lt;?php echo $photos[0]['thumbs'];?&gt;"/>
                        &lt;?php endif;?&gt;
                    </td>
                </tr>
                <tr>
                    <td>&lt;input type="text" name="info" id="info" size="20" value="" /&gt;&lt;/td>
                    &lt;input type="hidden" name="user_login_id" value="&lt;?php echo $user_login_id;?&gt;"&gt;
                    &lt;input type="hidden" name="user_id" value="&lt;?php echo $user_id;?&gt;"&gt;
                    &lt;input type="hidden" name="photos" value="&lt;?php echo $photos[0]['thumbs'];?&gt;"&gt;
                </tr>
                <tr><td>&lt;?php echo form_error('info','<div class="error">','</div>');?&gt;</td></tr>
                <tr>
                    <td>&lt;?php echo form_submit('valid_loran','Valider');?&gt;</td>
                </tr>
    &lt;?php echo form_close();?&gt;
            </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
#6

[eluser]InsiteFX[/eluser]
The call back needs to be in the controller with you other form code or it will not work!

InsiteFX
#7

[eluser]fuji2009[/eluser]
Hum i not understand the callback is in the controller function check_infos
#8

[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è




Theme © iAndrew 2016 - Forum software by © MyBB