1

The code below is a Codeigniter Event Calendar feature from here.

The calendar is click-able and you can enter data into the date field through a 'prompt' box. The data is then shown on the calendar date field.

However I am trying to use a JQUERY 'dialog' box with a 'spinner' as the input field rather than a 'prompt' box.

All the codes below are working perfectly accept for the JQUERY section at the end when I am trying use AJAX to POST the data. Codeigniter is unable to detect the POST data from the dialog box.

Could anyone please help?

     //CONTROLLER

    class Mycal extends CI_Controller {

    public function index() {
       $this->display();
    }

    function display($year = null, $month = null){

    if (!$year) {
        $year = date('Y');
    }
    if (!$month) {
        $month = date('m');
    }

    $this->load->model('Mycal_model');

    if($day = $this->input->post('day')){
        $this->Mycal_model->add_calendar_data(
            "$year-$month-$day",
            $this->input->post('data')
        );
    }

    $data['calendar'] = $this->Mycal_model->generate($year, $month);

    $this->load->view('mycal_view', $data); 
}

}

    //MODEL

    class Mycal_model extends CI_Model{

    function get_calendar_data($year, $month){

    $query = $this->db->select('date, data')->from('calendar')
        ->like('date', "$year-$month", 'after')->get();

    $cal_data = array();

    foreach ($query->result() as $row){
        $cal_data[substr($row->date,8,2)] = $row->data;
    }

    return $cal_data;
}

function add_calendar_data($date, $data){

    if($this->db->select('date')->from('calendar')
        ->where('date', $date)->count_all_results()) {

        $this->db->where('date', $date)->update('calendar', array(
            'date'=>$date,
            'data'=>$data
        ));

    }else{

        $this->db->insert('calendar', array(
            'date'=>$date,
            'data'=>$data
        ));
    }
}

function generate ($year, $month){

    $this->load->library('calendar', $this->conf);
    $cal_data = $this->get_calendar_data($year, $month);    
    return $this->calendar->generate($year, $month, $cal_data)      
}


    //VIEW

    <?php echo $calendar; ?>

    <div id="dialog-form" title="Select number of items">

    <p>
        <label for="spinner">Number of items:</label>
        <input id="spinner" name="spinner" value="0" />
    </p>

    </div>

    //JQUERY

    <script type="text/javascript">

$(document).ready(function() {

    $(function() {
        $( "#spinner" ).spinner({
            min: 0,
            max: 10,
            step: 1,
        });
    });

    $('.calendar .day').click(function() {
        $('#dialog-form').dialog("open");
    }); 

    $(function() {  
        $('#dialog-form')
            .attr('title', 'Number of items')
            .dialog({ 
                autoOpen: false,
                buttons: { 
                    'Ok': function() {
                        day_num = $(this).find('.day_num').html();
                        day_data = $("#spinner").val();


                            $.ajax({
                                url: window.location,
                                type: 'POST',
                                data: {
                                    day: day_num,
                                    data: day_data
                                },
                                success: function(msg){
                                    location.reload();
                                }
                            })      
                    },

                },

            });

    });
}); 
</script>
1
  • you are not specifying the the function name in the url!! Commented Jan 2, 2013 at 13:44

1 Answer 1

1

I guys thanks for the help I found out how to solved the problem. Here are my codes.

//JQUERY

    <script type="text/javascript">

$(document).ready(function() {
    $('.calendar .day').click(function() {
      $('#dialog-form').dialog("open");

      day_num = $(this).find('.day_num').html();
      day_data = $("#spinner").val();
    });


    $(function() {
        $( "#spinner" ).spinner({
            min: 0,
            max: 10,
            step: 1,
        });
    });



    $(function() {  
        $('#dialog-form')
            .attr('title', 'Number of items')
            .dialog({ 
                autoOpen: false,
                buttons: { 
                    'Ok': function() {

                            $.ajax({
                                url: window.location,
                                type: 'POST',
                                data: {
                                    day: day_num,
                                    data: day_data
                                },
                                success: function(msg){
                                    location.reload();
                                }
                            })      
                    },

                },

            });

    });
}); 
</script>
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.