My function add to cart didn't adding a food when i click button add to cart.
Controller:Asiabuffet.php
class Asiabuffet extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('cart');
$this->load->model('food_model');
}
public function index()
{
$data['data']=$this->food_model->get_all_food();
$this->load->view("front/asiabuffet",$data);
}
function add_to_cart(){
$data = array(
'id' => $this->input->post('id_food'),
'name' => $this->input->post('judul'),
'qty' => $this->input->post('quantity'),
);
$this->cart->insert($data);
echo $this->show_cart();
}
function show_cart(){
$output = '';
$no = 0;
foreach ($this->cart->contents() as $items) {
$no++;
$output .='
<tr>
<td>'.$items['name'].'</td>
<td>'.$items['qty'].'</td>
<td><button type="button" id="'.$items['rowid'].'" class="remove_cart btn btn-danger btn-sm">Cancel</button></td>
</tr>
';
}
return $output;
}
function load_cart(){
echo $this->show_cart();
}
function delete_cart(){
$data = array(
'rowid' => $this->input->post('row_id'),
'qty' => 0,
);
$this->cart->update($data);
echo $this->show_cart();
}
}
Models:Food_model.php
class Food_model extends CI_Model{
function get_all_food(){
$result=$this->db->get('food');
return $result;
}
}
Views:front/asiabuffet.php
<div class="col-md-12">
<?php foreach ($data->result() as $row) : ?>
<table class="table table-form">
<tbody>
<tr>
<td><?php echo $row->judul;?></td>
<td>
<div class="form-group">
<div class="col-md-2"></div>
<div class="col-md-8">
<input type="number" name="quantity" id="<?php echo $row->id_food;?>" value="0" class="quantity form-control">
</div>
<div class="col-md-2"></div>
</div>
</td>
<td>
<div class="col-md-12 text-center">
<button class="btn btn-primary btn-submit-card" data-id_food="<?php echo $row->id_food;?>" data-judul="<?php echo $row->judul;?>" onclick="add_cart(<?php echo $row->id_food;?>)">Add To Cart</button>
</div>
</td>
</tr>
</tbody>
</table>
<?php endforeach;?>
</div>
<div class="col-md-4">
<h4>Shopping Cart</h4>
<table class="table table-striped">
<thead>
<tr>
<th>Items</th>
<th>Qty</th>
<th>Actions</th>
</tr>
</thead>
<tbody id="detail_cart">
</tbody>
</table>
Jquery on view
<script type="text/javascript">
$(document).ready(function(){
$('.add_cart').click(function(){
var id_food = $(this).data("id_food");
var judul = $(this).data("judul");
var quantity = $('#' + id_food).val();
$.ajax({
url : "<?php echo site_url('asiabuffet/add_to_cart');?>",
method : "POST",
data : {id_food: id_food, judul: judul, quantity: quantity},
success: function(data){
$('#detail_cart').html(data);
}
});
});
$('#detail_cart').load("<?php echo site_url('asiabuffet/load_cart');?>");
$(document).on('click','.remove_cart',function(){
var row_id=$(this).attr("id");
$.ajax({
url : "<?php echo site_url('asiabuffet/delete_cart');?>",
method : "POST",
data : {row_id : row_id},
success :function(data){
$('#detail_cart').html(data);
}
});
});
});
</script>
I don't know what to do... Actually I made 2 view to adding cart to other view named checkout but it still not added. So, I make table on the same page to see if the food that being clicked adding to table or not. And it still cannot added to table.
Related
I'm using the checkbox to sending an email that already selected. after the email sent, the status sendinvoice change to Y. everything is fine when I select 1 checkbox. but when I choose multiple checkboxes, the function only update 1 checkbox
How to make it can run update function with multiple checkboxes?
the view code for checkbox and button below
<button type="button" class="btn waves-effect waves-light btn-info" id="btn-sentcitilink"> Sent Email</button>
<?php
foreach($result as $row){
?>
<form method="post" action="<?php echo base_url(); ?>cms/emailcitilink" id="sentemailcitilink">
<?php
}
?>
<table id="myTable" class="table table-bordered table-striped">
<thead>
<tr>
<th>Send Invoice </th>
<th>Booking ID</th>
</tr>
</thead>
<tbody>
<?php
foreach($result as $row){
?>
<tr>
<td>
<?php if($row['sendinvoice'] == 'N'){ ?>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" name="books[]" id="tableDefaultCheck/<?php echo $row['booking_id']?>" value="<?php echo $row['booking_id']?>">
<label class="custom-control-label" for="tableDefaultCheck/<?php echo $row['booking_id'] ?>"></label>
</div>
<?php } ?>
<?php if($row['sendinvoice'] == 'Y'){ ?>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="tableDefaultCheck3" checked disabled>
<label class="custom-control-label" for="tableDefaultCheck3"></label>
</div>
<?php } ?>
</td>
<td>
<div class="hover-link">
<a href="<?php echo base_url(); ?>cms/transaction/view/<?php echo $row['_id'] ?>">
<?php echo $row['booking_id'] ?>
</a>
</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<script>
$(document).ready(function() {
$("#check-all").click(function() {
if ($(this).is(":checked"))
$(".check-item").prop("checked", true);
else // Jika checkbox all tidak diceklis
$(".check-item").prop("checked", false);
});
$("#btn-sentcitilink").click(function() {
var confirm = window.confirm("Apakah Anda mengirim email data-data ini?");
if (confirm)
$("#sentemailcitilink").submit();
});
});
</script>
The controller code
function emailtocitilink(){
$books = $_POST['books'];
$get_trans = $this->cms_model->get_transaction_by_list_trip($tripsData);
foreach($get_trans as $row){
$arr_data = array(
'booking_id' => $row['TRANSIDMERCHANT'],
);
array_push($arr, $arr_data);
}
$data = $this->data;
$data['result'] = $arr;
$datas = array(
'SendINVOICE' => "Y"
);
$insert = $this->cms_model->update_transaction($datas, $books);
redirect(base_url().'cms/citilinktransaction/');
}
Model
function get_transaction_by_list_trip($TripUUID){
return $this->mongo_db
->where_in('TripUUID', $TripUUID)
->where(array('PAYMENTCHANNEL' => 'TESTINGCHANNEL'))
->order_by(array('transaction_date' => 'desc'))
->get('tr_transaction');
}
function update_transaction($datas, $books){
return $this->mongo_db->where_in('TRANSIDMERCHANT', $books)
->set($datas)
->update('tr_transaction',['multi' => TRUE]);
}
On model, it should be 'multiple' => true
Use update_all to update multiple records:
$this->mongo_db
->set($datas, ["multi" => true])
->where_in('TRANSIDMERCHANT', $books)
->update_all('tr_transaction');
Hi im working on my workshop tools project.
Now i have some strange action sometimes when i pressed the add to cart button (mine was named pinjam) it just going back to the login page because the session destroyed. Anyone has this strange thing happened? or Can you help me?
The scenario is like this..
I pressed the add to cart button on one of much tools that can i borrow, then it post to the add_to_cart function on my controller and reload the #cart_content div on that page with new added data with jquery / ajax
Controller Siswa
function index(){
$data['guru'] = $this->model_akun->getnamaguru();
$data['data']=$this->model_alat->getAll();
$this->load->view('siswa/dashboard',$data);
}
function add_to_cart(){
if($this->model_alat->validate_add_cart_item() == TRUE){
// Check if user has javascript enabled
if($this->input->post('ajax') != '1'){
redirect('siswa'); // If javascript is not enabled, reload the page with new data
}else{
echo 'true'; // If javascript is enabled, return true, so the cart gets updated
}
}
}function show_cart(){
$this->load->view('siswa/cart');
}
Model_Alat
function validate_add_cart_item(){
$id = $this->input->post('id_alat'); // Assign posted id_alat to $id
$cty = $this->input->post('quantity'); // Assign posted quantity to $cty
//$this->db->where('id_alat', $id); // Select where id matches the posted id
$query = $this->db->query('select * from alat where id_alat="'.$id.'"')->result(); // Select the products where a match is found and limit the query by 1
//$ss = $this->input->post('ajax');
//echo $query['id_alat'];
//echo "<script>alert(".$cty.");
// </script>";
// Check if a row has been found
if($query > 0){
foreach ($query as $row){
$data = array(
'id' => $id,
'qty' => $cty,
'price' => '0',
'name' => $row->nama_alat
);
$this->cart->insert($data);
return TRUE;
}
// Nothing found! Return FALSE!
}else{
echo "<script>alert('FALSE no rows :(');</script>";
return FALSE;
}
}
JQUERY
<script>
$(document).ready(function() {
/*place jQuery actions here*/
var link = "/weteies/index.php/"; // Url to your application (including index.php/)
$("div.subalat form").submit(function() {
// Get the product ID and the quantity
var id = $(this).find('input[name=id_alat]').val();
var qty = $(this).find('input[name=quantity]').val();
$.post(link + "siswa/add_to_cart", { id_alat: id, quantity: qty, ajax: '1' },
function(data){
// Interact with returned data
if(data == 'true'){
$.get(link + "siswa/show_cart", function(cart){ // Get the contents of the url cart/show_cart
$("#cart_content").html(cart); // Replace the information in the div #cart_content with the retrieved data
});
}else{
alert("Product does not exist");
}
});
});
});
siswa/cart (for viewing the cart list)
##siswa/cart view
<div class="table-responsive">
<?php echo form_open('siswa/update_cart'); ?>
<table class="table table-bordered">
<thead >
<tr>
<th>Alat</th>
<th>Jumlah</th>
<!--<th>Total</th>-->
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php $a=0; $b=0;foreach($this->cart->contents() as $items): ?>
<tr>
<!--<input type="hidden" id="id_peminjam" name="id_peminjam" value="'.$this->session->userdata('ses_id').'"/>-->
<td><?php echo form_hidden('rowid['.$a.']', $items['rowid']);
echo $items['name']; ?></td>
<td><?php echo form_input(array('name' => 'qty['.$a.']', 'value' => $items['qty'], 'maxlength' => '2'), '', 'class="form-control form-control-sm"'); ?></td>
<!--<td><button type="button" id="'.$items['rowid'].'" class="romove_cart btn btn-danger btn-sm">Cancel</button></td>-->
<td><?php echo form_submit('', 'Update', 'class="btn btn-accept btn-sm"');
$b=$a+1;?>
</tr>
<?php $a++; endforeach; ?>
</tbody>
</table>
<?php echo form_hidden('jumlah_alat', $b);
echo form_close();?>
<?php echo form_open('siswa/sub_cart'); ?>
<table class="table">
<tr>
<td >
<select name="id_guru" class="form-control form-control-sm">
<option>Pilih Guru</option>
<?php foreach($guru as $gurus): echo '<option value='.$gurus->id_akun.'>'. $gurus->nama .'</option>'; endforeach;?>
</select>
</td>
<td>
<?php $hitung=0; $b=0; foreach($this->cart->contents() as $items): ?>
<?php echo form_hidden('id_alat'.$hitung.'', $items['id']);
echo form_hidden('jumlah_pinjam'.$hitung.'', $items['qty']);
echo form_hidden('id_siswa', $this->session->userdata('ses_id'));
$b=$hitung+1;
$hitung++;
endforeach;
echo form_hidden('jumlah_alat', $b);
echo anchor('siswa/empty_cart', 'Hapus Semua', 'class="btn btn-danger btn-sm col-sm-5"'); ?>
<?php echo form_submit('', 'Pinjam!', 'class="btn btn-primary btn-sm col-sm-5"');?>
</td>
</tr>
</table>
<?php echo form_close(); ?>
</div>
FORM siswa/dashboard
<!DOCTYPE html>
<head>
<?php $this->load->view("admin/_partials/head.php") ?>
</head>
<body id="page-top">
<!-- Navbar-->
<?php $this->load->view("siswa/_partials/navbar.php") ?>
<div id="wrapper">
<!-- Sidebar-->
<?php $this->load->view("siswa/_partials/sidebar.php") ?>
<div id="content-wrapper">
<div class="container-fluid">
<div class="row ">
<div class="col-md-6">
<div class="card mb-3">
<h4 class="card-header">Alat Tersedia</h4>
<br>
<div class="row card-body">
<?php foreach ($data as $row) : ?>
<div class="col-md-6">
<div class="card mb-3">
<div class="card-header text-center"><?php echo $row->nama_alat;?>
</div>
<div class="card-body">
<div class="row">
<div class="col-md-7">
Tersedia
</div>
<div class="col-md-5">
<input value="<?php echo $row->jumlah;?>" class="form-control form-control-sm" readonly>
</div>
</div>
<div class="subalat">
<?php echo form_open(''); ?>
<div class="row">
<div class="col-md-7">
Mau Brp?
</div>
<div class="col-md-5">
<?php echo form_hidden('id_alat', $row->id_alat);
echo form_input('quantity', '1', 'maxlength="2" class="form-control form-control-sm"'); ?>
</div>
</div>
<br>
<?php echo form_submit('add', 'Pinjam','class="btn btn-success btn-block col-md"'); ?>
<?php echo form_close(); ?>
</div>
</div>
</div>
</div>
<?php endforeach;?>
</div>
</div>
</div>
<div class="col-md-6">
<div class="card mb-3">
<h4 class="card-header">List Pinjam</h4>
<!--<div class="card-body">-->
<div id="cart_content">
<?php $this->load->view('siswa/cart'); ?>
</div>
<!--</div>-->
<div class="card-footer small text-muted">
Jika jumlah alat nya 0(nol), alat akan dihapus. Page rendered in <strong>{elapsed_time}</strong> seconds.
</div>
</div>
</div>
</div><!-- /.row -->
</div><!-- /.content-fluid -->
<!-- Sticky Footer -->
<?php $this->load->view("siswa/_partials/footer.php") ?>
</div>
<!-- /.content-wrapper -->
</div>
<!-- /#wrapper -->
<?php $this->load->view("siswa/_partials/scrolltop.php") ?>
<!-- Modal-->
<?php $this->load->view("siswa/_partials/modal.php") ?>
<!-- Js-->
<?php $this->load->view("siswa/_partials/js.php") ?>
</body>
<script>
$(document).ready(function() {
/*place jQuery actions here*/
var link = "/weteies/index.php/"; // Url to your application (including index.php/)
$("div.subalat form").submit(function() {
// Get the product ID and the quantity
var id = $(this).find('input[name=id_alat]').val();
var qty = $(this).find('input[name=quantity]').val();
$.post(link + "siswa/add_to_cart", { id_alat: id, quantity: qty, ajax: '1' },
function(data){
// Interact with returned data
if(data == 'true'){
$.get(link + "siswa/show_cart", function(cart){ // Get the contents of the url cart/show_cart
$("#cart_content").html(cart); // Replace the information in the div #cart_content with the retrieved data
});
}else{
alert("Product does not exist");
}
});
});
});
</script>
</html>
Login controller
class Login extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model("model_login");
}
function index(){
$this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|trim');
if($this->form_validation->run()==FALSE){
$session = $this->session->userdata('isLoggedin');
if($session == FALSE){
$this->load->view('login');
}
else{
redirect('');
}
}
else{
$email=$this->input->post('email');
$password=$this->input->post('password');
$cek_akun=$this->model_login->auth_akun($email,$password);
if($cek_akun->num_rows() > 0){
$user_data=$cek_akun->row_array();
$this->session->set_userdata('isLoggedin',TRUE);
$this->session->set_userdata('ses_id',$user_data['id_akun']);
$this->session->set_userdata('ses_nama',$user_data['nama']);
if($user_data['level']=='admin'){ //level admin
$this->session->set_userdata('level','admin');
redirect('admin');
}
else if($user_data['level']=='aspiran'){ //level aspiran
$this->session->set_userdata('level','aspiran');
redirect('aspiran');
}
else if($user_data['level']=='guru'){ //level guru
$this->session->set_userdata('level','guru');
redirect('guru');
}
else if($user_data['level']=='siswa'){ //level siswa
$this->session->set_userdata('level','siswa');
redirect('siswa');
}
}
else{
$this->load->view('login');
echo "<script>alert('Failed Login: Check your username and password!');
</script>";
}
}
}
function logout(){
$this->session->sess_destroy();
$url=base_url('');
redirect($url);}}
I'm working on CodeIgniter project,. In my web-app I'm filtering my data-tables processing on server using drop-down lists with selecting multiple values from drop-down list box. I'm getting a proper output.
My view code is:
<div class="content-wrapper">
<div class="box-body">
<form name="listproperty" action="" method="post" role="form" id="form-filter">
<div class="row">
<div class="col-md-3">
<label>Area: </label>
<select class="form-control", name="area_name" id="area_name">
<option value="0">Select Area</option>
<?php
$area_id;
foreach ($areaList as $area) { ?>
<option value="<?= $area->area_id_primary; ?>" <?php if ($area->area_id_primary == $area_id) { echo "selected='selected'"; } ?>><?= $area->area_name; ?></option>
<?php } ?>
</select>
</div>
<div class="col-md-3">
<label>City: </label>
<select class="form-control" name="city_name" id="city_name" multiple="">
<option value="">Select City</option>
<?php $ct = explode(' ', $city);
foreach ($propertyCityList as $propertyCity) {
$selected = false;
foreach ($ct as $usercity) {
if ($usercity == $propertyCity->city_id_primary) {
$selected = true;
break;
}
} ?>
<option value="<?= $propertyCity->city_id_primary; ?>" <?php if($selected === true) { echo "selected='selected'"; } ?>><?= $propertyCity->city_name; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row"> </div>
<div class="row">
<div class="pull-right">
<div class="col-md-12">
<button type="button" id="btn-filter" class="btn btn-success" style="margin-right: 25px;">Filter</button>
<button type="button" id="btn-reset" class="btn btn-default">Reset</button>
</div>
</div>
</div>
</form>
</div><hr>
<div class="box-body">
<table class="table table-striped table-bordered" id="listpropertyData" cellspacing="0" width="100%">
<thead>
<tr>
<th width="10%">Added Date</th>
<th width="10%">ASYS No.</th>
<th width="18%">Address</th>
<th width="10%">City</th>
<th width="15%" style="text-align: center;">Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Added Date</th>
<th>ASYS No.</th>
<th>Address</th>
<th>City</th>
<th style="text-align: center;">Action</th>
</tr>
</tfoot>
</table>
</div>
<script type="text/javascript">
var property;
$(document).ready(function() {
$("#area_name").select2();
$("#city_name").select2();
property = $('#listpropertyData').DataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "<?= base_url('Controller/getPropertyDatatable'); ?>",
"type": "POST",
"dataType": "JSON",
"data": function ( data ) {
data.area_name = $('#area_name').val();
data.city_name = $('#city_name').val();
}
},
"dom": '<"top"fli>rt<"bottom"p><"clear">',
"lengthMenu": [[25, 50, 100, 200, -1], [25, 50, 100, 200, "All"]],
"columnDefs": [
{
"targets":[7],
"orderable":false
},
],
});
$('.dataTables_filter input[type="search"]').css(
{'width':'450px','display':'inline-block'}
);
$('#btn-filter').click(function(){ //button filter event click
property.ajax.reload(); //just reload table
});
$('#btn-reset').click(function(){ //button reset event click
$('#form-filter')[0].reset();
property.ajax.reload();
window.location.reload(); //just reload table
});
});
</script>
My controller code:
public function listProperty()
{
# code...
$data['areaList'] = $this->property_model->areaList();
$data['propertyCityList'] = $this->property_model->propertyCityList();
$this->global['pageTitle'] = 'RoxAI-ePro : Property List';
$this->loadViews("property/listProperty", $this->global, $data, NULL);
}
public function getPropertyDatatable()
{
# code...
$listProperty = $this->property_model->getPropertyDatatable();
$data = array();
foreach ($listProperty as $property) {
# code...
$added_on=$property->property_added_on;
$added_on_date = str_replace('/', '-', $added_on);
$property_added_on_date=date('d/m/Y', strtotime($added_on_date));
$row = array();
$row[] = $property_added_on_date;
$row[] = $property->property_asys_number;
$row[] = $property->property_address;
$row[] = $property->city_name;
$row[] = 'Action';
$data[] = $row;
}
$output = array(
'draw' => $_POST['draw'],
'recordsTotal' => $this->property_model->countPropertyAll(),
'recordsFiltered' => $this->property_model->countPropertyFiltered(),
'data' => $data,
);
echo json_encode($output);
}
My question is how I can pass that drop-down list values in URL so I can get same result directly if I'm trying to copy-paste URL and open it in another browser with same selection of values in drop-down?
Below are some screenshots of the UI
This is first window which i get as soon as i login
Using jQuery i've used slidetoggle function as below for feedback.
now when i click reply button for each row bootstrap-modal popup is triggered.
I'm confused here. As i click send it should stay in the same window. it works for the first one using ajax. but for 2nd one onwards it refreshes the page.
Below are the Code
Ajax code
// Ajax post for email sending
$(document).ready( function() {
$("#mailsubmit").click(function(event) {
event.preventDefault();
var recipient = $("input#recipient").val();
var subject = $("input#subject").val();
var message = $("textarea#message").val();
jQuery.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "index.php/user_authentication/send_reply",
dataType: 'json',
data: {recipient: recipient, subject: subject, message:message},
success: function(result) {
if (result)
{
// Show Entered Value
console.log("Success");
}
}
});
});
});
Table HTML in UI
<table class="table table-hover">
<thead>
<tr>
<th id="nameCol">ID </th>
<th>NAME</th>
<th >EMAIL</th>
<th>MOBILE</th>
<th>MESSAGE</th>
<th>DATE & TIME</th>
<th>STATUS</th>
<th>REPLY</th>
</tr>
</thead>
<tbody>
<?php if( is_array( $fbrecords ) && count( $fbrecords ) > 0 )
foreach($fbrecords as $r) { ?>
<tr class="idrow">
<td id="tdname" style="display:none;" > <?php echo $r->id; ?></td>
<td><?php echo $r->fullname; ?></td>
<td><?php echo $r->email; ?></td>
<td><?php echo $r->mobile; ?></td>
<td><?php echo $r->message; ?></td>
<td><?php echo $r->jtime; ?></td>
<td> <?php $data=array(
'data-row' => $r->id, //ID of the row
'name'=>'status',
'row' => '12px',
'id' => 'status',
'selected'=>$r->status,
'class'=>'statusClass'
);
$data_status = array(
'none' => 'none',
'A&A' => 'Attended & Acted',
'YTA' => 'Yet to Attend',
);
echo form_dropdown($data, $data_status, set_value('status')); ?> </td>
<td><button type="button" class="btn btn-sm btn-success emlbtn" data-toggle="modal" data-target="#myModal-<?php echo $r->id; ?>"> Reply to <?php $fname=explode(" ",$r->fullname); echo $fname[0]; ?></button>
<!-- Modal -->
<div class="modal fade" id="myModal-<?php echo $r->id; ?>" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Reply to <?php $fname=explode(" ",$r->fullname); echo $fname[0]; ?> </h4>
</div>
<div class="modal-body">
<?php
echo "<br/>";
echo $this->session->flashdata('email_sent');
echo "<br/>";
echo form_open(); ?>
<label>Recipient :</label>
<input type="text" id="recipient" name="recipient" value= "<?php echo $r->email; ?>" style="cursor:not-allowed" disabled ></input>
<br> </br>
<label>Subject :</label>
<input type="text" id="subject" name="subject" value= "Re: <?php $msg=$r->message; echo substr($msg,0,20); echo "......"; ?>" ></input>
<br> </br>
<label>Message :</label>
<textarea value="Your Message" id="message" name="message" style="margin: 0px; width: 564px; height: 131px;"></textarea>
<br> </br>
<?php
$data = array(
'id' => 'mailsubmit',
'value' => 'Send Mail'
);
echo form_submit($data,'submit' );
echo form_close(); ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
Send_reply in Controller
public function send_reply(){
$data = array(
'from_email' => "tabsheer.abdulla#ionidea.com",
'recipient' => $this->input->post('recipient'),
'from_name' => "tabsheerabdulla",
'subject' => $this->input->post('subject'),
'message' => $this->input->post('message'),
);
echo json_encode($data);
$this->load->library('email');
$this->email->from($data['from_email'], $data['from_name']);
$this->email->to($data['recipient']);
$this->email->subject($data['subject']);
$this->email->message($data['message']);
//Send mail
if($this->email->send()) {
$this->session->set_flashdata("email_sent","<span> * Email sent successfully. </span> ");
//$this->load->view('adminhp');
} else {
$this->session->set_flashdata("email_sent","<span> * Error in sending Email.</span> ");
// $this->load->view('adminhp');
}
}
Anybody as a Soluton for this!???
Because you are creating a bootstrap modal for every row, and every modal has elements with same IDs which is not valid HTML in W3C specification.
So as you have multiple submit buttons with #mailsubmit jQuery always targets only the first one which is why it only works for first row.
Either use class name for targeting submit buttons and target the inputs of currently open modal to submit correct data or rewrite your modal window generation so that only one is generated on page and use javascript to properly fill the inputs with correct row values when the modal opens.
And a side note: Using tons of question marks in questions makes you look like a 12 year old Bieber fan.
Im quiet new to codeigniter and i am having some trouble setting up my shopping cart. plzz help!!
This is my model:
class shop_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_all() {
$results = $this->db->get('product')->result();
return $results;
}
function get($id) {
$results = $this->db->get_where('product', array('id' => $id))->row_array();
$result = $results[0];
//result()
return $result;
}
}
my controller:
class shop extends CI_Controller {
public function __construct()
{
parent::__construct();
//$this->load->library(array('form_validation', 'email','pagination'));
$this->load->database();
$this->load->model('shop_model');
}
public function index()
{
$data['products'] = $this->shop_model->get_all();
//print_r($data['products']);
$this->load->view('template/header');
$this->load->view('watch_stop/vprod_list', $data);
$this->load->view('template/footer');
}
public function prod_cart(){
$data['title'] = 'Shopping Cart | Watch Stop';
$this->load->view('template/header');
$this->load->view('watch_stop/vcart', $data);
$this->load->view('template/footer');
}
function add(){
$prod_list = $this->shop_model->get($this->input->post('id'));
$id = $this->input->post('id');
$insert = array(
'id' => $this->input->post('id'),
'qty' => 1,
'price' => $prod_list->price,
'name' => $prod_list->title
);
$this->cart->insert($insert);
print_r($this->cart->contents());
//redirect('shop/prod_cart');
}
}
my cart (view) page:
<div class="row">
<div class="col-md-9">
<?php if ($cart = $this->cart->contents()): ?>
<div id="cart">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Item Name</th>
<th>Option</th>
<th>Price</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach ($cart as $item): ?>
<tr>
<td><?php echo heading($item['brand'].' - '.$item['gender'], 5).br().$item['title'];?></td>
<td><?php ?></td>
<td><?php echo $item['subtotal']; ?></td>
<td class="remove"><?php anchor('shop/remove'.$item['rowid'], '<i class="fa fa-times fa-2x"></i>'); ?> </td>
<tr>
<?php endforeach; ?>
<tr class="total">
<td colspan="2"><strong>Total:</strong></td>
<td>LKR <?php echo $this->cart->total(); ?></td>
</tr>
</tbody>
</table>
</div> <!--table-responsive end-->
</div> <!--cart end-->
<?php endif; ?>
</div> <!--col-md-9 end-->
</div> <!--.row end-->
my products list (view) page (this page is populated via another controller and model and works perfectly):
<div class="row na_top ws-brand-head">
<!--column 1 start-->
<div class="col-md-12">
<?php
echo heading($sub_head, 2);
echo '<hr>';
?>
</div> <!--column 1 end-->
</div> <!--row end-->
<div class="row">
<?php echo $this->session->flashdata('msg'); ?>
<?php foreach($products as $prod_list): ?>
<!--Column 2 start-->
<div class="col-md-3 ws-brand">
<div id="products" class="naprod naprod-mar">
<?php
$na_1 = array(
'src' => base_url().$prod_list['image'],
'height' => '150',
'alt' => $prod_list['title']
);
echo form_open('shop/add');
echo heading($prod_list['stock'], 5);
echo '<div class="na-img">'.img($na_1).'</div>';
echo '<div class="nacont">';
echo anchor(site_url('product/'.$prod_funct.'/'.$prod_list['id']),'<p class="na-btn">VIEW</p>');
?>
<!--<input type="text" id="id" name="id" value="<?php //echo $prod_list['id'] ; ?>" style=" display:none;"/>-->
<input type="hidden" name="id" value="<?php echo $prod_list['id'] ; ?>" />
<button type="submit" name="action" class="na-btn"><i class='fa fa-shopping-cart fa-lg'></i></button>
<?php
echo '</div>';
echo br();
echo heading('LKR '.$prod_list['price'], 5);
echo '<div id="'.$prod_list['brand'].'_'.$prod_list['gender'].'_'.$prod_list['id'].'">'.$prod_list['title'].'</div>';
echo form_close();
?>
</div> <!--naprod naprod-mar end-->
</div> <!--column 2 end-->
<?php endforeach; ?>
</div> <!--row end-->
When i try to load the shop/add method im getting the following errors:
1)Trying to get property of non-object in my controller shop: line 40 and 41. That is the line where i have created the $insert array 'price' and 'name'.
You have to verify if there is catched $prod_list after you try to catch it with your shop model.. (I am not quite sure what your method get is returning but false check should be enough)
function add(){
$prod_list = $this->shop_model->get($this->input->post('id'));
if( ! $prod_list ) {
echo "Product doesn't exists";
exit;
}
$id = $this->input->post('id');
$insert = array(
'id' => $this->input->post('id'),
'qty' => 1,
'price' => $prod_list->price,
'name' => $prod_list->title
);
$this->cart->insert($insert);
print_r($this->cart->contents());
//redirect('shop/prod_cart');
}