CodeIgniter Forums

Full Version: [Solved] Onclick not working with php code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using calendar library and I can get data displayed on my dates from database in my array on model.

Where I have $calendar[$event['day']] = I can return html code also for calendar view data.

The on click is not working correct it is still submitting the form when I click on cancel? Why would it do that and how to fix it?

Example:


PHP Code:
<?php

    public 
function get_events($year$month) {
 
       $calendar = array();

 
       $this->db->where('year'$year);
 
       $this->db->where('month'$month);
 
       $query $this->db->get('calendar');

 
       $results $query->result_array();

 
       foreach ($results as $event) {

 
           if (array_key_exists($event['day'], $calendar)) {


 
                   
                $calendar
[$event['day']] =     $calendar[$event['day']] .'
                                            <div class="clearfix">
                                            <div class="pull-left">
                                            <ul class="list-unstyled">
                                            <li>'
 
                                           anchor(base_url('report/events/'$year .'/'$month .'/'$event['calendar_id']), $event['event']) . '
                                            </li>
                                            </ul>
                                            </div>
                                            <div class="pull-right">'
 
                                           .anchor(base_url('report/events/edit' .'/'$event['calendar_id']), '<i class="fa fa-pencil"></i>', array('class' => 'text-primary''data-toggle' => 'tooltip'' data-placement' => 'top''title' => 'Edit Event')).'
                                            
                                            <i type="button" onclick="confirm(\'Are you sure?\') ? $(\'#form-event\').submit() : false;" class="fa fa-trash text-danger" style="cursor: pointer;"></i>

                                            <form id="form-event" method="post" enctype="multipart/form-data" id="form-user">
                                            <input type="hidden" name="delete_id" value="'
.$event['calendar_id'].'">
                                            </form>
        
                                            </div>
                                            </div>'
;
 
               
            
} else {
 
               
                $calendar
[$event['day']] = '<div class="clearfix">
                                            <div class="pull-left">
                                            <ul class="list-unstyled">
                                            <li>' 
 
                                           anchor(base_url('report/events/'$year .'/'$month .'/'$event['calendar_id']), $event['event']) . '
                                            </li>
                                            </ul>
                                            </div>
                                            <div class="pull-right">'
 
                                           .anchor(base_url('report/events/edit' .'/'$event['calendar_id']), '<i class="fa fa-pencil"></i>', array('class' => 'text-primary''data-toggle' => 'tooltip'' data-placement' => 'top''title' => 'Edit Event')).'
                                    
                                            <i type="button" onclick="confirm(\'Are you sure?\') ? $(\'#form-event\').submit() : false;" class="fa fa-trash text-danger" style="cursor: pointer;"></i>

                                            <form id="form-event" method="post" enctype="multipart/form-data" id="form-user">
                                            <input type="hidden" name="delete_id" value="'
.$event['calendar_id'].'">
                                            </form>
        
                                            </div>
                                            </div>'
;
 
           }
 
       }

 
       return $calendar;
 
   
I found best method for me. On the form open add on submit.




<form id="form-event" method="post" enctype="multipart/form-data" onsubmit="return confirm(\'Are you sure you want to remove this!\')";>