Welcome Guest, Not a member yet? Register   Sign In
Help with adding a jquery alert box after form is correctly submitted
#21

[eluser]LuckyFella73[/eluser]
As far as I know you have to load the database library in your callback function
even if you allready loaded it in your controller constructor because only the
callback function is called in your case and not the whole controller.
#22

[eluser]iwillsoarlikeaneagle[/eluser]
Understood!

Ok! Thanks for all the help man! Really! Keep it up!
:-)
#23

[eluser]noobs[/eluser]
heloo i use your source code to my application but did'nt work for me....to insert data in my table can you tell me how...insert data in table use your script...thx before...frend
#24

[eluser]LuckyFella73[/eluser]
So everything works besides saving the submitted data into your table?
Please post your controller and model code then I can have a look into that.
#25

[eluser]noobs[/eluser]
yup...is working..besides insert data to my table...if i load my model in controller and i click data save...data still empty on my table...

-- controller --
Code:
function save_user()
{
$this->load->library('form_validation');
// this load form validation on cofig folder
if($this->form_validation->run('add_user') == FALSE)
{
            $array = '{ "message" : "Input not valid" }';
            echo $array;
}
else
{
$this->load->model('User_model');            
$add_data = $this->User_model->add_user();
if($add_data == TRUE)
{
       $array = '{ "message" : "Saving data success" }';
       echo $array;
}
else
{
       $array = '{ "message" : "Saving Failed" }';
       echo $array;
}
}
$this->load->view('add_user');
}

-- model --
Code:
function add_user()
{
$this->db->set('user_name',set_value('user_name'));
$this->db->insert('users');

return TRUE;
}
#26

[eluser]LuckyFella73[/eluser]
I have never seen this usage in models and can't find it in the user guide either:
Code:
$this->db->set('user_name',set_value('user_name')); // set_value
Maybe it should work .. don't know

Try the following code and see what you get. Note that you'll have
to edit the lines around "$db_data = array(" according to the name
attributes of your input fields!

Code:
# controller:
function save_user()
{
    $this->load->library('form_validation');

    // this load form validation on cofig folder
    if($this->form_validation->run('add_user') == FALSE)
    {
        $array = '{ "message" : "Input not valid" }';
        echo $array;
    }
    else
    {
        $this->load->model('User_model');
        
        $db_data = array(
            'username' => $this->input-post('username'),
            'password' => $this->input-post('username')// and so on
        );

        $add_data = $this->User_model->add_user($db_data);

        if($add_data === FALSE)
        {
            $array = '{ "message" : "Saving Failed" }';
            echo $array;
        }
        else
        {
            $array = '{ "message" : "Saving data success" }';
            echo $array;
        }
    }
    $this->load->view('add_user');
}
Code:
# model:
function add_user($data)
{
    if ( $this->db->insert('users', $data) )
    {
        return $this->db->insert_id();
    }
    else
    {
        return FALSE;
    }
}
#27

[eluser]noobs[/eluser]
still not working my bro... i try to your script but same..nothing happen...

Code:
// Js in <head></head>

$(document).ready(function()
{
    $("#submit_item").click(function ()
    {
        var username = $('#username').val();
      

        $.post("form/save_user", { "username" : username },
        function(data)
        {
            $('#box_message').removeClass("msg-hide");
            $('#box_message').addClass("msg-show");

            $('#box_message').html(data.message);
        }, 'json');
    });

    $("#reset_form").click(function ()
    {
        $('#username').val('');
      
    });

});

// css
<style type="text/css">
div.msg-hide {display:none;}
div.msg-show {display:block;}
</style>

Code:
// Form
<div id="box_message" class="msg-hide">hidden temp text</div>
&lt;!-- --&gt;
Full Name:<br />
    &lt;?php
    $attrib = array('id' => 'username',
                    'name' => 'username'
                    );
    echo form_input($attrib).form_error('username'); ?&gt;
    
       &lt;?php
    $attrib = array('id' => 'submit_item',
                    'name' => 'submit_item',
                    'value' => 'save'
                    );
    echo form_submit($attrib); ?&gt;
    &lt;?php
    $attrib = array('id' => 'reset_form',
                    'name' => 'reset_form',
                    'value' => 'Reset'
                    );
    echo form_reset($attrib);
    ?&gt;
&lt;?php echo form_close(); ?&gt;

thx your suggestion bro.... i am confuse use jquery in codeigniter Sad
#28

[eluser]LuckyFella73[/eluser]
Can you explain more detailed where the code breaks?

I mean, when submitting the form do you get the json response
"Saving data success" while the data is not saved into DB
or it's just that nothing happens? Or do you allways get
the response "Saving Failed" ?
#29

[eluser]noobs[/eluser]
nothing happens bro....if i click submit button...




Theme © iAndrew 2016 - Forum software by © MyBB