0

i am newbie in codeigniter and jquery but the website i am maintaining now uses this framework and language,.,.the problem is that i have these text fields and hidden fields in a page,,.i want to get the values of these input fields through jquery,.,passed these through $.post of jquery to a Controller,.,.i know how to track the flow but i do not know how to get the passed value in my controller and i am totally newbie in codeigniter and jquery,,i want to learn and at the same time finished the task,.,. heres my code in my view page..

 <?php $date = date('m/d/Y');
    $ts = strtotime($date);
    $year = date('o', $ts);
    $week = date('W', $ts);
    for($i = 1; $i <= 7; $i++) {
           $ts = strtotime($year.'W'.$week.$i);
        ?><input type="text" name="days" class="days" /><input type="hidden" id="date_now" name="date_now" value="<?php print date("Y-m-d", $ts); ?>" />

    } 
?>

and my jquery for text input

$(".saveTimeSheet").click(function() { 
    var days_array     = [];
    var date_now_array = [];

    $('.days').each(function() {
            days_array.push($(this).val());
    });
    $.post("<?php print base_url().'index.php/MyController/saveTimeTable'?>", {days_array: days_array},
        function(data){
            if(data=='success')
            {
                alert('success');
            }
            else{
                error_message(data);
            }
    });
 });

MyController Code...

function saveTimeTable()
{
   $idnum=$this->session->userdata('id');       
       $duration=$this->input->post('days_array')*3600;
       $this->mmyhr->modeSaveTimeTable($idnum, $duration);
}

my Model code(mmyhr)

function modeSaveTimeTable($idnum, $duration)
{
   $this->db->set('employee_id', $idnum);
   $this->db->set('duration', $duration);
   $this->db->insert('hs_hr_time_event');
 }

could anyone help me,.,.please....

5
  • Please take the time to use proper grammar, spelling, and format your code. Commented Nov 28, 2012 at 3:51
  • I agree please properly format. The fact that you broke out of PHP tags here ?><td><?php just for a TD tag makes it harder to read not to mention harder to maintain. Commented Nov 28, 2012 at 3:59
  • So what exactly is or isn't happening? Commented Nov 28, 2012 at 4:05
  • So the problem is with the database part of the code? You can receive the array of data from the jQuery post data and the data the model receives ($idnum & $duration) are getting the correct values?) ?? Commented Nov 28, 2012 at 4:08
  • 1
    I still don't get it because your days_array will be received as array. How can you multiply it directly without using loop? $this->input->post('days_array')*3600 Commented Nov 28, 2012 at 4:33

1 Answer 1

1

Based on your code above your controller should be like this:

function saveTimeTable()
{
    $idnum=$this->session->userdata('id');
    $days_array = $this->input->post('days_array');

    foreach($days_array as $day){
        $duration=$day*3600;
        $this->mmyhr->modeSaveTimeTable($idnum, $duration);
    }    
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.