Just want to know how to find the match value on the dropdown list and display the value as current selected for update.
this is my table query and displayed on page with update link beside each row. All update link is working and the value displayed on hidden textbox. My problem is just on one column $trandescription, this will be post on dropdown.
this is my display table.
while($row = mysql_fetch_array($query))
{
echo "
<tr>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['patientid']."</td>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['trandate']."</td>
<td style='border:1px solid; color:gray' width='600px'>".$row['trandescription']."</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>".$row['tranquantity']."</td>
<td style='border:1px solid; color:gray' width='90px' align='right'>".number_format($row['tranunitprice'],2)."</td>
<td style='border:1px solid; color:gray' width='150px' align='right'>".number_format($row['tranamount'],2)."</td>
<td style='border:1px solid; color:gray'><a href='updatebillindex.php?update=$row[id]'>update</a></td>
<td style='border:1px solid; color:gray'><button class='btn btn-default btn-sm';><a href='updatebillindex.php?update=$row[0]'>edit
<span class='glyphicon glyphicon-trash'></span></a></button></td>
</tr> ";
this is my update page
<?php
if (isset($_GET['update']))
{
$id = $_GET['update'];
$query = mysql_query("SELECT * FROM transaction where id = '$id'") or die ("could not search");
$count = mysql_num_rows($query);
while ($rows = mysql_fetch_array($query)) {
$id = $rows['id'];
$tranid = $rows['tranid'];
$trandate = $rows['trandate'];
$patientid = $rows['patientid'];
$transactiontype = $rows['transactiontype'];
$trandescription = $rows['trandescription'];
$tranquantity = $rows['tranquantity'];
$tranunitprice = $rows['tranunitprice'];
$tranamount =$rows['tranamount'];
$gettrandescription = $rows['trandescription'];
}
}
?>
<form action="billindex.php" method="POST">
<input type="hidden" name="id" value="<?php echo "$id"; ?>">
<input type="hidden" name="tranid" value="<?php echo "$tranid"; ?>">
<input type="hidden" name="patientid" value="<?php echo "$patientid"; ?>">
<input type="hidden" name="trandate" value="<?php echo "$trandate"; ?>">
<input type="hidden" name="transactiontype" value="<?php echo "$transactiontype"; ?>">
<input type="text" name="trandescription" value="<?php echo "$trandescription"; ?>">
<input type="hidden" name="tranquanity" value="<?php echo "$tranquantity"; ?>">
<input type="hidden" name="tranunitprice" value="<?php echo "$tranunitprice"; ?>">
<input type="hidden" name="tranamount" value="<?php echo "$tranamount"; ?>">
<input type="submit" name="update" value="Update">
</form>
<?php
echo "$trandescription"; // find the match value on dropdown list and display this value.
?>
this is my dropdown list on the update page
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Medicine
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<form action="transaction.php" method="POST">
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading"><h7>Medicine Type : </h7></div>
<div class="panel-body">
<select name="selectmedicine" class="form-control col-sm-4" id="medicinename">
<option id="0" style="width:100px"></option>
<?php
$medicine = mysql_query("SELECT * FROM medicine");
while ($row = mysql_fetch_array($medicine)) {
echo '<option id="' . $row['medicinename'] . '"';
echo ' value="' . $row['medicineid'] . '"';
if($row['medicineid'] == $row['medicinename']) {
echo ' selected="selected"';
}
echo '>';
echo $row['medicinename'];
echo '</option>';
}
?>
</select>
</div>
</div>
</div>
Related
how to insert select option value in database using checkbox?When I click checkbox and click enroll button ,select option doesn't inserting selected value.I have 3 options(Regular,Retake,Recourse) in "examtype" table but when I choose more than one subject select option not working perfectly. Here is my code...
here is my select option image
<?php
if (isset($_POST['enroll']))
{
if (!empty($_POST['chk1']))
{
if (isset($_POST['et']))
{
$roll_no = $_SESSION['roll_no'];
//$selectbox1 = $_POST['et'];
foreach($_POST['chk1'] as $checkbox1)
{
foreach($_POST['et'] as $selectbox1)
//for($i=0;$i<sizeof($selectbox1);$i++)
$values = explode("|" , $checkbox1);
$values1= explode("|" , $selectbox1);
$course_id= $values[0];
$semester= $values[1];
$course_name= $values[2];
$selectbox1=$values1[0];
$sql="INSERT INTO pendingcourse(roll_no,course_id,semester,course_name,exam_type,status) VALUES('$roll_no','$course_id','$semester','$course_name','$selectbox1',0)";
$stmt = $connect->prepare($sql);
$stmt->execute();
$checkbox1='';
$selectbox1='';
}
header("location:coursetable.php");
}
}
}
?>
<form action="coursetable.php" method="post" enctype="multipart/form-data">
<div class="container mt-3" >
<div class="accordion mb-4" id="accordionExample" >
<div class="accordion-item" style="background-color: rgb(0, 225, 255);">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button collapsed fw-bold" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="false" aria-controls="collapseOne" style="background: #AAFFA9;">
1st Semester
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse" aria-labelledby="headingOne" >
<div class="accordion-body">
<table class="table table-bordered border-primary text-center">
<thead>
<tr>
<th scope="col-1">Course Id</th>
<th scope="col-1">Semester</th>
<th scope="col-7">Course</th>
<th scope="col-1">Exam Type</th>
<th scope="col-1">Select</th>
<th scope="col-2">Result</th>
</tr>
</thead>
<tbody>
<?php
$stmt = $connect->query("SELECT course_id,semester,course_name FROM coursetable Where semester = '1st' ");
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($rows as $row)
{
$course_id = $row['course_id'];
$semester = $row['semester'];
$course_name = $row['course_name'];
?>
<tr>
<td scope="row"> <?php echo $course_id?></td>
<td > <?php echo $semester ?></td>
<td ><?php echo $course_name ?></td>
<td>
<select name="et[]" class="form-select form-select-sm" aria-label=".form-select-sm example">
<?php
$stmt1 = $connect->query("SELECT * from examtype");
$rows1 = $stmt1->fetchAll(PDO::FETCH_ASSOC);
foreach($rows1 as $row1) {
?>
<option value="<?php echo $row1['exam_type']; ?>"><?php echo $row1['exam_type']; ?></option>
<?php
}
?>
</select>
</td>
<td>
<input type="checkbox" name="chk1[]" value="<?php echo $row['course_id']?>|<?php echo $row['semester']?>|<?php echo $row['course_name']?>|<?php echo $row1['exam_type']?>">
<label class="form-check-label" for="flexCheckDefault">
</label>
</td>
<td></td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-md-2 col-xs-6 offset-md-5 mb-3">
<button type="submit" name="enroll" class="btn btn-warning mt-2">Enroll</button>
</div>
</div>
</div>
</form>
Place the input field inside a form and add
enctype="multipart/form-data"
<select name="et[]" class="form-select form-select-sm" aria-label=".form-select-sm example" multiple>
try this
add multiple in select
SOLVED:
<?php
if (isset($_POST['enroll']))
{
if (!empty($_POST['chk1']))
{
if (!empty($_POST['et']))
{
$roll_no = $_SESSION['roll_no'];
$selectbox1 = $_POST['et'];
$selectbox11=implode(',',array_filter($selectbox1));
$i=0;
foreach($_POST['chk1'] as $checkbox1)
{
$selectbox111 = array_diff(explode(",", $selectbox11),array(""));
$selectbox1111 = $selectbox111[$i];
$values = explode("|" , $checkbox1);
$course_id= $values[0];
$semester= $values[1];
$course_name= $values[2];
$sql="INSERT INTO pendingcourse(roll_no,course_id,semester,course_name,exam_type,status) VALUES('$roll_no','$course_id','$semester','$course_name','$selectbox1111',0)";
$stmt = $connect->prepare($sql);
$stmt->execute();
$checkbox1='';
$i++;
}
}
}
}
?>
I use codeigniter pagination also here i use ajax to search so that the paging does not works. While click the paging link the full page is get reloaded .Actually i am not familiar with ajax so i dont know how this problem can be solved.Any help is appreciated.
Controller
public function chrgs_ajs_result()
{
$type = $this->input->post('catg');
$sdate = $this->input->post('start_date');
$edate = $this->input->post('end_date');
$result['error'] = "";
$result['res'] = "";
$result['res'] = $this->chrgs_edit_report_model->get_edit_amount($type,$sdate,$edate);
$config['base_url'] = base_url() . 'index.php/payment_edit/chrgs_ajs_result';
$config['total_rows'] = count($result['res']);
$config['per_page'] = 15;
$config["uri_segment"] = 3;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$result['res'] = $this->chrgs_edit_report_model->get_edit_amount($type,$sdate,$edate,$config["per_page"], $page);
$result["links"] = $this->pagination->create_links();
//$result['res'] = $this->chrgs_edit_report_model->get_edit_amount($type,$sdate,$edate);
// echo "<pre>";
// print_r($result['res']);
if (!empty($result['res']))
{
$this->load->view('edit_charg_ajax_result',$result);
}
else
{
echo "No Result Found";
}
}
Ajax Result page
<table border="1" class="mainTable" cellpadding="0" cellspacing="0">
<tr> <?php if (isset($links)) { echo $links; } ?> </tr>
<tr style="background-color:#F2FAFF;color:#660">
<td width="3%">Sl No</td>
<td width="8%">Track Number</td>
<td width="8%">Old <?php echo $type; ?></td>
<td width="8%">New <?php echo $type; ?></td>
<td width="30%">Reason</td>
<td width="10%">Date</td>
<td width="10%">Requested By</td>
<td width="10%">Approved By</td>
<td width="10%">Approved IP</td>
</tr>
<?php
$i = 1;
foreach ($res as $value)
{
?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $value['track_no']; ?></td>
<td><?php echo $value['old_value']; ?></td>
<td><?php echo $value['new_value']; ?></td>
<td><?php echo $value['reason']; ?></td>
<td><?php echo $value['added_on']; ?></td>
<td><?php echo $value['requested_by']; ?></td>
<td><?php echo $value['approved_by']; ?></td>
<td><?php echo $value['ip']; ?></td>
</tr>
<?php
$i++;
} ?>
Main Result page
<section>
<div class="content">
<div class="row">
<div class="col-md-12" style="margin-left: 2%;">
<div class="box">
<form class="form-horizontal" id="form">
<fieldset>
<div class="box-body">
<div class="col-md-12 row div1">
<div class="form-group col-md-4" style="margin-left: 80px;">
<label style="margin-top: 20px;"><b>Types:</b></label>
<div class="input-group" id="error">
<select class="form-control" id="catg" name="catg" style="width: 134%; border-radius: 5px;">
<option value="">--Select--</option>
<option value="charges">Charges</option>
<option value="delivery_at">Delivery_at</option>
<option value="doc_country">Doc_country</option>
<option value="doctype">Doctype</option>
<option value="mfa">Mfa</option>
<option value="package">Package</option>
<option value="sub_package">Sub_package</option>
</select>
</div>
</div>
<div class="form-group col-md-3" >
<label class="lmarg"><b>Start Date:</b></label>
<div class="input-group">
<div class="input-group-addon"> <i class="fa fa-calendar"></i> </div>
<input type="text" name="start_date" id="start_date" class="form-control datepicker">
</div>
</div>
<div class="form-group col-md-3" style="margin-left: 2px;">
<label class="lmarg"><b>End Date:</b></label>
<div class="input-group">
<div class="input-group-addon"> <i class="fa fa-calendar"></i> </div>
<input type="text" name="end_date" id="end_date" class="form-control datepicker">
</div>
</div>
<div class="form-group">
<label label class="lmarg" style="visibility: hidden;">search</label>
<div class="col-md-1 input-group">
<input type="button" class="btn pull-right" id="search_charge_edit" value="search">
</div>
</div>
</div>
</div>
</fieldset>
</form>
<div style="margin-top: 3%;margin-right: 1%;">
<div id="result" ></div>
</div></div>
</div>
</div>
</div>
$("#search_charge_edit").on("click",function(){
var controller_function = "<?php echo base_url();?>index.php/payment_edit/chrgs_ajs_result";
var post_data = $("#form").serialize();
$.ajax({
type:"post",
url:controller_function,
data:post_data,
success:function(data)
{
//alert(data);
//$('#form').trigger("reset");
$('#result').html(data);
}
});
});
This is the table form which i will select the row to edit by using Button Edit
$query = "SELECT * FROM tbl_document LIMIT $start, $end";
$result = mysqli_query($con,$query);
echo "<table border='1' width='300' height='160' align = center id='result'>";
echo '<tr>
<th width="80">ID</th>
<th width="200">Title</th>
<th width="260">Presented To</th>
<th width="260">Presented By</th>
<th width="160">Date Submitted</th>
<th>Location</th>
<th width="17%">Option</th>
</tr>';
while($row = mysqli_fetch_array($result)){
echo "<tr align = center >";
echo "<td width='20' height='60'>" .$row['ID']. "</td>";
echo "<td width='120' height='60'>" .$row['Title']. "</td>";
echo "<td>" .$row['Presented_To']. "</td>";
echo "<td>" .$row['Presented_By']. "</td>";
echo "<td>" .$row['Date_Submitted']. "</td>";
echo "<td>" .$row['Location']. "</td>";
echo "<td width='17%'>";
?>
<p>
<button onclick="document.getElementById('edtID').style.display='block'" value="<?php echo $row['ID']; ?>" class="w3-btn w3-blue w3-border-large w3-circle" id="edit" name="edit" style="width:60%"><i class="fa fa-edit"></i> Edit</button>
This is the second code this form is modal which i click the button from the table and the modal show and you can edit but what is missing of my code?
<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<p>
<label class="w3-label w3-text-black"><strong>Title:</strong></label>
<input class="w3-input w3-hover-light-blue w3-animate-input w3-border-large w3-light-grey" style="width:100%" type="text" id="title" name="title" placeholder="Title" value=<?php $row['Title']; ?>required></span>
</p>
</form>
On your second form (your modal), I see no echo to display the value of your title
<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<p>
<label class="w3-label w3-text-black"><strong>Title:</strong></label>
<input class="w3-input w3-hover-light-blue w3-animate-input w3-border-large w3-light-grey" style="width:100%" type="text" id="title" name="title" placeholder="Title" value=<?php echo $row['Title']; ?>required></span>
</p>
</form>
Also, for your first form, you can write it this way
<table border='1' width='300' height='160' align=center id='result'>
<tr>
<th width="80">ID</th>
<th width="200">Title</th>
...
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
echo "<tr align = center >";
echo "<td width='20' height='60'>" .$row['ID']. "</td>";
echo "<td width='120' height='60'>" .$row['Title']. "</td>";
...
?>
<p>
<button onclick="document.getElementById('edtID').style.display='block'" value="<?php echo $row['ID']; ?>" class="w3-btn w3-blue w3-border-large w3-circle" id="edit" name="edit" style="width:60%">
<i class="fa fa-edit"></i> Edit
</button>
</p>
<?php
}
?>
And finally, you should start using PDO for everything related to the database.
first,I have table display from database, in each row it has update button.
second, i have a four (4) collapsible select option form.
third, the select option form has value from database. this value is also present in the column on the table above(first).
Now what i want is when i update the value from the row on the table, the collapsible form will open then the value from the table will display on the select option form.
Here's my code. the code below cant open the collapsible form and display the value on the select option form.
displaytable.php
<?php
$output='';
$noresult='';
if (isset($_POST['search']))
{
$globalpid = $_POST['search'];
$query = mysql_query("SELECT * FROM transaction where patientid ='$globalpid' order by trandate asc") or die ("could not search");
$count = mysql_num_rows($query);
$globalpid = mysql_real_escape_string($globalpid);
if($count == '' && $countname==0)
{
?>
<?php require_once 'search.php'; ?>
<div class="container" style="padding-left:30px">
<br><p><font color="#0B3861"><?php echo "There was no search results!"; ?> </font>
</div>
</div>
<?php }else{
?>
<?php
$total = '';
$add=mysql_query("SELECT SUM(tranamount) from transaction where patientid = $globalpid");
while($row=mysql_fetch_array($add))
{
$totalamount=$row['SUM(tranamount)'];
}
require_once 'transactionheadermenu.php';
?>
<div class="container" style="padding-top:0px; padding-left:30px; padding-right:30px;">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title"><font color="#2B547E"><?php echo "$outputname";?></font></h3></div>
<div class="panel-body">
<?php require_once 'billpatientquery.php';?>
<?php
echo "<table class='table table-hover';>
<tr>
<td style='border:1px solid; color:gray' width='145px' align='center'>Patient ID</td>
<td style='border:1px solid; color:gray' width='145px' align='center'>Date</td>
<td style='border:1px solid; color:gray' width='600px' align='center'>Item / Description</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>Quantity</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>Price</td>
<td style='border:1px solid; color:gray' width='150px' align='center'>Amount</td>
<td style='border:1px solid; color:gray' width='30px' align='center'>Update</td>
<td style='border:1px solid; color:gray' width='30px' align='center'>Delete</td>
</tr>";
while($row = mysql_fetch_array($query))
{
echo "
<tr>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['patientid']."</td>
<td style='border:1px solid; color:gray' width='145px' align='center'>".$row['trandate']."</td>
<td style='border:1px solid; color:gray' width='600px'>".$row['trandescription']."</td>
<td style='border:1px solid; color:gray' width='90px' align='center'>".$row['tranquantity']."</td>
<td style='border:1px solid; color:gray' width='90px' align='right'>".number_format($row['tranunitprice'],2)."</td>
<td style='border:1px solid; color:gray' width='150px' align='right'>".number_format($row['tranamount'],2)."</td>
<td style='border:1px solid; color:gray'><a href='updatebillindex.php?update=$row[id]'>update</a></td>
<td style='border:1px solid; color:gray'><button class='btn btn-default btn-sm';><a href='updatebillindex.php?update=$row[0]'>edit
<span class='glyphicon glyphicon-trash'></span></a></button></td>
</tr> ";
}
echo "</table>";
?>
</div>
</div>
</div>
<?php }
} ?>
updatebillindex.php
?php
if (isset($_GET['update']))
//
{
$id = $_GET['update'];
// //$tranid = $_POST['update'];
//$patientid = $_POST['update'];
//$trandate = $_POST['update'];
//$getname = $_POST['update'];
$query = mysql_query("SELECT * FROM transaction where id = '$id'") or die ("could not search");
$count = mysql_num_rows($query);
while ($rows = mysql_fetch_array($query)) {
$id = $rows['id'];
$tranid = $rows['tranid'];
$trandate = $rows['trandate'];
$patientid = $rows['patientid'];
$transactiontype = $rows['transactiontype'];
$trandescription = $rows['trandescription'];
$tranquantity = $rows['tranquantity'];
$tranunitprice = $rows['tranunitprice'];
$tranamount =$rows['tranamount'];
$gettrandescription = $rows['trandescription'];
}
}
if (isset($_POST['selectmedicine'])) {
$gettrandescription=$_POST['medicineid'];
}
if (isset($_POST['selectroomquantity'])) {
$tranquantity=$_POST['quantity'];
}
?>
<script type="text/javascript">
$('#collapseone').collapseone({
toggle: true
});
</script>
<option value="<?php echo $trandescription; ?>" <?php if($trandescription==$gettrandescription){ echo "selected";} ?> ><?php echo $gettrandescription; ?></option>
<option value="<?php echo $tranquantity; ?>" <?php if($tranquantity==$tranquantity){ echo "selected";} ?> ><?php echo $tranquantity; ?></option>
<form action="billindex.php" method="POST">
<input type="hidden" name="id" value="<?php echo "$id"; ?>">
<input type="hidden" name="tranid" value="<?php echo "$tranid"; ?>">
<input type="hidden" name="patientid" value="<?php echo "$patientid"; ?>">
<input type="hidden" name="trandate" value="<?php echo "$trandate"; ?>">
<input type="hidden" name="transactiontype" value="<?php echo "$transactiontype"; ?>">
<input type="hidden" name="trandescription" value="<?php echo "$trandescription"; ?>">
<input type="hidden" name="tranquanity" value="<?php echo "$tranquantity"; ?>">
<input type="hidden" name="tranunitprice" value="<?php echo "$tranunitprice"; ?>">
<input type="hidden" name="tranamount" value="<?php echo "$tranamount"; ?>">
<input type="submit" name="update" value="Update">
</form>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Medicine
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<form action="transaction.php" method="POST">
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading"><h7>Medicine Type : </h7></div>
<div class="panel-body">
<select name="selectmedicine" class="form-control col-sm-4" id="medicinename">
<option id="0" style="width:100px"></option>
<?php
$medicine = mysql_query("SELECT * FROM medicine");
while ($row = mysql_fetch_array($medicine)) {
echo '<option id="' . $row['medicinename'] . '"';
echo ' value="' . $row['medicineid'] . '"';
if($row['medicineid'] == $row['medicinename']) {
echo ' selected="selected"';
}
echo '>';
echo $row['medicinename'];
echo '</option>';
}
?>
</select>
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading panel-height:20px":><h7>Quantity : </h7></div>
<div class="panel-body">
<select name="selectmedicinequantity" class="form-control col-md-4" id="quantityname">
<option id="0" style="width:100px"></option>
<?php
$medicinequantity = mysql_query("SELECT * FROM quantity");
while ($displayquantity = mysql_fetch_array($medicinequantity)) {
$quantityid = $displayquantity['id'];
$quantityname = $displayquantity['quantityname'];
//$quantityprice = $displayquantity['quantityprice'];
?>
<option id=" <?php echo $displayquantity['quantityid']; ?>"><?php if($displayquantity['quantityid'] == $displayquantity['quantityname']) echo 'selected="selected"'; ?><?php echo $displayquantity['quantityname'] ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
This is cart view
<div id="cart" >
<div id="text">
<?php $cart_check = $this->cart->contents();
// If cart is empty, this will show below message.
if(empty($cart_check))
{
echo 'To add products to your shopping cart click on "Add to Cart" Button';
} ?> </div>
<table id="table" border="0" cellpadding="5px" cellspacing="1px" class="table table-hover" style="padding: 0px;margin: 0px;text-align: center">
<?php
// All values of cart store in "$cart".
if ($cart = $this->cart->contents()): ?>
<tr id= "main_heading">
<td width="5%">Serial</td>
<td width="30%">Name</td>
<td width="20%">Price</td>
<td width="10%">Qty</td>
<td width="25%">Amount</td>
<td width="10%">Cancel Product</td>
</tr>
<?php
// Create form and send all values in "shopping/update_cart" function.
echo form_open('index.php/cart/update_cart');
$grand_total = 0;
$i = 1;
foreach ($cart as $item):
// echo form_hidden('cart[' . $item['id'] . '][id]', $item['id']);
// Will produce the following output.
// <input type="hidden" name="cart[1][id]" value="1" />
echo form_hidden('cart[' . $item['id'] . '][id]', $item['id']);
echo form_hidden('cart[' . $item['id'] . '][rowid]', $item['rowid']);
echo form_hidden('cart[' . $item['id'] . '][name]', $item['name']);
echo form_hidden('cart[' . $item['id'] . '][price]', $item['price']);
echo form_hidden('cart[' . $item['id'] . '][qty]', $item['qty']);
?>
<tr>
<td>
<?php echo $i++; ?>
</td>
<td>
<?php echo $item['name']; ?>
</td>
<td>
$ <?php echo number_format($item['price'], 2); ?>
</td>
<td>
<?php echo form_input('cart[' . $item['id'] . '][qty]', $item['qty'], 'maxlength="3" size="1" style="text-align: center"'); ?>
</td>
<?php $grand_total = $grand_total + $item['subtotal']; ?>
<td>
$ <?php echo number_format($item['subtotal'], 2) ?>
</td>
<td>
<?php
// cancle image.
?>
<a href="<?php echo base_url() ;?>index.php/cart/remove/<?php echo $item['rowid']?>">
<img src="<?php echo base_url(); ?>assets/images/cart/cart_cross.jpg" width='25px' height='20px'>
</a
<?php
// echo anchor('index.php/cart/remove/' . $item['rowid'], $path); ?>
</td>
<?php endforeach; ?>
</tr>
<tr class="info">
<td colspan="2" align="left"> <b>Order Total: $ <span style="font-weight: bold"> <?php
//Grand Total.
echo number_format($grand_total, 2); ?></span></b></td>
<?php // "clear cart" button call javascript confirmation message ?>
<td colspan="4" align="right"><input type="button" class ='fg-button teal' value="Clear Cart" onclick="clear_cart()">
<?php //submit button. ?>
<input type="submit" class ='fg-button teal' value="Update Cart">
<?php echo form_close(); ?>
<!-- "Place order button" on click send "billing" controller -->
<!-- <input type="button" class ='fg-button teal' value="Place Order" onclick="window.location = 'index.php/cart/billing_view'">-->
<button id="placeorder" type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="#mdo" style="margin-left: 5px">Place Order</button>
</td>
</tr>
<?php endif; ?>
</table>
</div>
After click on placeholder button(above code) it will open bootstrap model.
Code of that is
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true" style="text-align: left">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">Tour Inquire Form</h4>
</div>
<?php
$grand_total = 0;
// Calculate grand total.
if ($cart = $this->cart->contents()):
foreach ($cart as $item):
$grand_total = $grand_total + $item['subtotal'];
endforeach;
endif;
?>
<form action="<?php echo base_url();?>index.php/cart/send_mail" method="POST" id="mailform">
<div class="modal-body">
<div class="form-group">
<label for="recipient-name" class="control-label">Name:</label>
<input type="text" class="form-control" name="name">
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">E-Mail</label>
<input type="email" class="form-control" name="mail">
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">Contact Number</label>
<input type="number" class="form-control" name="mob">
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">Total Value of Your Product</label>
<input type="text" class="form-control" name="price" value="<?php echo $grand_total;?>" readonly>
</div>
<div class="form-group">
<label for="message-text" class="control-label">Message:</label>
<textarea class="form-control" id="message-text" rows="5" name="msg"></textarea>
</div>
</div>
<div class="modal-footer">
<input type="button" class="btn btn-default" data-dismiss="modal" value="Close">
<input type="submit" class="btn btn-primary" name="submit" value="Send Mail">
</div>
</form>
</div>
</div>
</div>
After user click on Send Mail, I need to send mail get data(html codes) from some other div(Mentioned below, Name mail_table)
and data should send to my mail controller.
<div id="mail_table" style="display: none">
<table cellpadding="6" cellspacing="1" style="width:100%" border="0">
<tr>
<th>QTY</th>
<th>Product Name</th>
<th style="text-align:right">Item Price</th>
<th style="text-align:right">Sub-Total</th>
</tr>
<?php $i = 1; ?>
<?php foreach ($this->cart->contents() as $items): ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<tr>
<td><?php echo $items["qty"] ?></td>
<td>
<?php echo $items['name']; ?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>
<p>
<?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>
<strong><?php echo $option_name; ?>:</strong> <?php echo $option_value; ?><br />
<?php endforeach; ?>
</p>
<?php endif; ?>
</td>
<td style="text-align:right"><?php echo $this->cart->format_number($items['price']); ?></td>
<td style="text-align:right">$<?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="2"> </td>
<td class="right"><strong>Total</strong></td>
<td class="right">$<?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
</div>
all works fine with ajax.
<script>
$(function(){
$( "#placeorder" ).click(function(event){
event.preventDefault();
var htmlString = $("#mail_table").html();
$.ajax({
type : 'post',
url : '<?php echo base_url();?>index.php/cart/send_mail',
data : $('#form').serialize() + "table" + htmlString
});
});
});
</script>
but in controller when I assign data to
public function send_mail()
{
$name = $_POST['name'];
$mail = $_POST['mail'];
$mob = $_POST['mob'];
$price = $_POST['price'];
$msg = $_POST['msg'];
// $to =
$to = 'mail#gmail.com';
$to = 'my#gmail.com';
$subject = 'Enquiry from ' .$name;
$message = $_POST['table']; //Line 144
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
// $headers .= 'From: '.$_REQUEST['email'];
if(mail($to, $subject, $message, $headers))
{
}
}
But I'm getting error
A PHP Error was encountered
Severity: Notice
Message: Undefined index: table
Filename: controllers/cart.php
Line Number: 144
any idea???
Problem is this line of code in your view ajax. With this code table not send in your parameter. Also your form id is mailform
data : $('#form').serialize() + "table" + htmlString
It would be
data : $('#mailform').serialize() + "&table=" + encodeURIComponent(htmlString)