Welcome Guest, Not a member yet? Register   Sign In
Hello I have a question
#1

[eluser]fuji2009[/eluser]
Hello Guys i have a question I m new with Codeigniter but i don t find how resolve my problem:

I create a controller with an index and the view :

Test -> test_view

In view I have insert modal Jquery ( Div hidden ) In each div i Have a form : form1 form2 form3 ect


In Test , I want do : if this->form_validation for form1 send email1

if this->form_validation for form2 update this ect, how do plz ?

Thanks You .
#2

[eluser]fuji2009[/eluser]
Someone ? plzzz
#3

[eluser]Cristian Gilè[/eluser]
You can use different method in the controller to validate the forms (one method for each form) or you can use only one method and discriminate between the different input submit name.

Take a look at this solution: http://ellislab.com/forums/viewthread/178330/#845441

If you need more help, please, post your code.


Cristian Gilè
#4

[eluser]fuji2009[/eluser]
Thanks you for exemple my profile.view :

[removed]
jQuery(document).ready(function() {
jQuery("#become_friend").dialog({
bgiframe: true, autoOpen: false, height: 250,width:440, modal: true
});
jQuery("#become_enemy").dialog({
bgiframe: true, autoOpen: false, height: 250,width:440, modal: true
});
});
Code:
<div id="become_friend" title="Devenir Ami">
    &lt;?php echo form_open('profile/become_friends/'.$user_id,'name="become_friend"');?&gt;
            <table width="400px">
                <tr>
                    <td><label for="info" class="float">Souhaitez vous devenir l'ami de &lt;?php echo $username_profil;?&gt;</label></td>
                    <td>&lt;?php if ($photos == false): ?&gt;
                        <img width="65px" height="65px;" src="../../../users/Default/Hrogfdsgdfh.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;?php echo form_error('info','<div class="error">','</div>');?&gt;</td></tr>
                &lt;input type="hidden" name="user_id" value="&lt;?php echo $user_login_id;?&gt;"&gt;
                &lt;input type="hidden" name="user2_id" value="&lt;?php echo $user_id;?&gt;"&gt;
                <tr>
                    <td>&lt;?php echo form_submit('become_friend','Become his friend');?&gt;
                    &lt;?php echo form_submit('Cancel','Cancel');?&gt;</td>
                </tr>
    &lt;?php echo form_close();?&gt;
            </table>
</div>
<div id="become_enemy" title="become enemy">
    &lt;?php echo form_open('profile/become_enemy/'.$user_id,'name="become_enemy"');?&gt;
            <table width="400px">
                <tr>
                    <td><label for="info" class="float">Be enemy with &lt;?php echo $username_profil;?&gt;</label></td>
                    <td>&lt;?php if ($photos == false): ?&gt;
                        <img width="65px" height="65px;" src="../../../users/Default/Hrogfdsgdfh.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;?php echo form_error('info','<div class="error">','</div>');?&gt;</td></tr>
                &lt;input type="hidden" name="user_id" value="&lt;?php echo $user_login_id;?&gt;"&gt;
                &lt;input type="hidden" name="user2_id" value="&lt;?php echo $user_id;?&gt;"&gt;
                <tr>
                    <td>&lt;?php echo form_submit('become_enemy','Become his enemy');?&gt;
                    &lt;?php echo form_submit('Cancel','Cancel');?&gt;</td>
                </tr>
    &lt;?php echo form_close();?&gt;
            </table>
</div>

And my controller :

Code:
function index{
.......
}
function become_friends($user_id){
        $data['page'] = 'profile';
        $data['title'] = 'become Friend';
        
        $this->load->model('profile_model');
        
        $this->form_validation->set_rules('become_friend','become friend','trim|required|xss_clean');
        
        if ($this->form_validation->run())
        {
            $data['page'] = 'profile';
            $data['title'] = 'friend of'. $username_profil;
            extract($_POST);
            
            $become_friends = array(
                'user1_id' => $user_login_id,
                'user2_id' => $user_id,
                'type' => 'friend',
                'valide' => 0,
                'created_at' => date('Y-m-d h:i:s',now())
            );
            $this->profile_model->become_friends($become_friends);
            echo 'You are now friends';
        }
        redirect('profile/index/'.$username);
    }
function become_friends($user_id){
        $data['page'] = 'profile';
        $data['title'] = 'become Friend';
        
        $this->load->model('profile_model');
        
        $this->form_validation->set_rules('become_enemy','become enemy','trim|required|xss_clean');
        
        if ($this->form_validation->run())
        {
            $data['page'] = 'profile';
            $data['title'] = 'Enemy of'. $username_profil;
            extract($_POST);
            
            $become_enemy = array(
                'user1_id' => $user_login_id,
                'user2_id' => $user_id,
                'type' => 'friend',
                'valide' => 0,
                'created_at' => date('Y-m-d h:i:s',now())
            );
            $this->profile_model->become_enemy($become_enemy);
            echo 'You are now Enemy';
        }
        redirect('profile/index/'.$username);
    }

What is wrong ?
Thank you
#5

[eluser]Cristian Gilè[/eluser]
In your controller you have two functions with the same name. I don't see the become_enemy function.


Cristian Gilè




Theme © iAndrew 2016 - Forum software by © MyBB