I using codeigniter.I have a form in view page that post the data to a controller class.I dont have much idea about this. Can someone help me code? My view page:
<?php
//form data
$attributes = array('class' => 'form-horizontal', 'id' => '');
$indiatimezone = new DateTimeZone("Asia/Kolkata" );
$date = new DateTime();
$date->setTimezone($indiatimezone);
//form validation
echo validation_errors();
echo form_open('admin/billing/ticket_add', $attributes);
?>
<div id="ticket">
<table style=" border-collapse: collapse;">
<tr>
<th>Employee</th>
<th>Start Time</th>
<th>ID</th>
<th>Mins</th>
</tr>
<tr id="1" ondblclick="myid(this)">
<input type="text" name="id" value="<?php echo $date->format( 'H:i' ); ?>"/>
<td contenteditable="true"><?php echo form_dropdown('employee', $options_category, set_value('employee'),'style="border-radius:0px; height:15px; font-size:10px; width:70px"');?></td>
<td contenteditable="true"><input type="text" name="start_time" value="<?php echo $date->format( 'H:i' ); ?>"/></td>
<td contenteditable="true" ondblclick="mylist()"><input type="text" name="pid" value="<?php echo set_value('pid'); ?>"/></td>
<td contenteditable="true" class="nr"><input type="text" name="mins" value="<?php echo set_value('mins'); ?>"/></td>
</tr>
<tr id="2" ondblclick="myid(this)">
<td contenteditable="true"><?php echo form_dropdown('employee', $options_category, set_value('employee'),'style="border-radius:0px; height:15px; font-size:10px; width:70px"');?></td>
<td contenteditable="true"><input type="text" name="start_time" value="<?php echo $date->format( 'H:i' ); ?>"/></td>
<td contenteditable="true" ondblclick="mylist()"><input type="text" name="pid" value="<?php echo set_value('pid'); ?>"/></td>
<td contenteditable="true" class="nr"><input type="text" name="mins" value="<?php echo set_value('mins'); ?>"/></td>
</tr>
</div>
<?php echo form_close(); ?>
Here I send my data to controller function ticket_add.Below is my tickect_add function in controller.
public function ticket_add()
{
if ($this->input->server('REQUEST_METHOD') === 'POST')
{
$this->form_validation->set_rules('employee', 'employee');
$this->form_validation->set_rules('start_time', 'start_time');
$this->form_validation->set_rules('pid', 'pid');
$this->form_validation->set_rules('mins', 'mins');
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><a class="close" data-dismiss="alert">×</a><strong>', '</strong></div>');
//if the form has passed through the validation
if ($this->form_validation->run())
{
$data_to_store = array(
'employee' => $this->input->post('employee'),
'start_time' => $this->input->post('start_time'),
'pid' => $this->input->post('pid'),
'mins' => $this->input->post('mins'),
);
}
}
$this->billing_model->store_bill($data_to_store);
$data['main_content'] = 'admin/billing/ticket_page';
$this->load->view('includes/template', $data);
}
Here I get the posted value and send them to model file to store my data. How to do this.Can someone please kindly help me?
are you not doing that already?
$this->billing_model->store_bill($data_to_store);
this line is passing $data_to_store to function store_bill inside billing_model
You should debug in your model to check for issue... Considering this as your function in billing_model
public function store_bill($data_to_store)
{
$this -> db -> insert( 'your_table_name', $data_to_store );
// try this
echo $this->db->last_query();
// you will get complete insert query from above line...
// Execute it in phpmyadmin to check for any error..
}