Unable to send orderId variable to php file using this code please help
below is the jquery script i am trying to use but it is senting only one variable which has onblur option not other..
I am trying to send variable to change the value in database on blur but not able to make it
Plase help me get a solution on this at the earliest
function submitPrice() {
$("#loaderIcon").show();
jQuery.ajax({
url: "updatestatus.php",
data: 'finalprice=' + $("#fprice").val(),
data: 'orderId=' + $("#orderId").val(),
type: "POST",
success: function(data) {
$("#order-availability-status").html(data);
$("#loaderIcon").hide();
},
error: function() {}
});
}
function submitReso() {
$("#loaderIcon").show();
jQuery.ajax({
url: "updatestatus.php",
data: 'resolution=' + $("#reso").val(),
data: 'orderId=' + $("#orderId").val(),
type: "POST",
success: function(data) {
$("#order-availability-status").html(data);
$("#loaderIcon").hide();
},
error: function() {}
});
}
function submitState() {
$("#loaderIcon").show();
jQuery.ajax({
url: "updatestatus.php",
data: 'status=' + $("#status").val(),
data: 'orderId=' + $("#orderId").val(),
type: "POST",
success: function(data) {
$("#order-availability-status").html(data);
$("#loaderIcon").hide();
},
error: function() {}
});
}
<table class="table">
<tbody class="table-body">
<tr style="padding-top:15px">
<td><strong>Current Order Status</strong></label>
</td>
<td>::</td>
<td>
<p><span class="statecolor badge badge-pill"><?php echo $row["status"];?></span></p>
</td>
</tr>
<tr style="padding-top:15px">
<td><strong>Current Cost</strong></h4>
</td>
<td>::</td>
<td>
<h4>₹
<?php echo $row["finaltotal"]; ?>
</h4>
</td>
</tr>
<form action="" method="post" id="priceform">
<tr style="padding-top:15px">
<td><strong>Enter Final Repair Cost</strong></h4>
</td>
<td>::</td>
<input type="hidden" name="orderId" value="<?php echo $row['orderId'];?>">
<td><input type="text" class="form-control form-control-sm" placeholder="Enter Price" id="fprice" name="finalprice" onBlur="submitPrice()"> </td>
<td></td>
</tr>
</form>
<tr style="padding-top:15px">
<td><strong>Current Resolution</strong></h4>
</td>
<td>::</td>
<td>
<h4>
<?php echo $row["resolution"]; ?>
</h4>
</td>
</tr>
<form action="" method="post" id="resoform">
<tr style="padding-top:15px">
<input type="hidden" name="orderId" value="<?php echo $row['orderId'];?>">
<td><strong>Update Resolution</strong></h4>
</td>
<td>::</td>
<td><textarea class="form-control form-control-sm" placeholder="Enter Final Resolution" id="reso" name="resolution" onBlur="submitReso()"></textarea></td>
<td> <span id="order-availability-status"></span></td>
</tr>
</form>
<form action="updatestatus.php" method="post" id="statusform">
<tr style="padding-top:15px">
<td><strong>Change Order Status</strong></h4>
</td>
<td>::</td>
<td class="align-middle text-right">
<input type="hidden" name="orderId" value="<?php echo $row['orderId'];?>">
<select name="status" id="status" class="form-control form-control-sm" onChange="submitState()">
<option value="">Change Status</option>
<option value="confirmed">confirmed</option>
<option value="pending_inspection">pending_inspction</option>
<option value="due">due</option>
<option value="paid">paid</option>
<option value="picked_up">pickedup</option>
<option value="shipped">shipped</option>
<option value="complete">complete</option>
<option value="onhold">onhold</option>
<option value="pending_pickup">Pending_pickup</option>
</select>
</td>
<td><span id="order-availability-status"></span></td>
</tr>
<td><button class="bt_main">Go Back</button> </td>
</tr>
</form>
</tbody>
</table>
You can only have one data: property in an object. To send multiple parameters, use a single data: property containining an object with all the parameters. For example:
function submitPrice() {
$("#loaderIcon").show();
jQuery.ajax({
url: "updatestatus.php",
data: {
finalPrice: $("#fprice").val(),
orderId: $("#orderId").val()
},
type: "POST",
success: function(data) {
$("#order-availability-status").html(data);
$("#loaderIcon").hide();
},
error: function() {}
});
}
Related
<html>
<body>
<div class="content">
<fieldset>
<div>
<h1>Student Details</h1>
</div>
<form method="">
<table>
<tr>
<td><label>Student ID:</label></td>
<td><input type="text" name="StuID"></td>
<td><input type="submit" name="find" value="Find"></td>
</tr>
<tr><td></td></tr>
<tr>
<td><label>Student IC:</label></td>
<td><input type="text" name="StuIC"></td>
</tr>
<tr>
<td><label>School ID:</label></td>
<td><input type="text" name="SchID"></td>
</tr>
<tr>
<td><label>Student Name:</label></td>
<td><input type="text" name="StuNAME"></td>
</tr>
<tr>
<tr>
<td><label>Gender:</label></td>
<td>
<select name="Gender">
<option>--Gender--</option>
<option>Male</option>
<option>Female</option>
</select>
</td>
</tr>
<tr>
<td><label>Nationality:</label></td>
<td><input type="text" name="Nationality"></td>
</tr>
<tr>
<td><label>Race:</label></td>
<td>
<select name="Race">
<option>--Race--</option>
<option>Malay</option>
<option>Indian</option>
<option>Chinese</option>
<option>Other</option>
</select>
</td>
</tr>
<tr>
<td><label>Religion:</label></td>
<td>
<select name="Religion">
<option>--Religion--</option>
<option>Muslim</option>
<option>Buddist</option>
<option>Hindu</option>
<option>Christian</option>
<option>Other</option>
</select>
</td>
</tr>
<tr>
<td><label>Telephone Number:</label></td>
<td><input type="text" name="TelNo"></td>
</tr>
</tr>
<tr>
<td><input type="submit" name="add" value="Add"></td>
<td><input type="submit" name="update" value="Update"></td>
<td><input type="submit" name="delete" value="Delete"></td>
</tr>
</table>
</form>
</fieldset>
</div>
</body>
</html>
This is my form, the user can find the data by insert the ID and click "Find" and the data will display in the form. With the same form, user can update the data with just change data in the form and click "Update" and the data will update in database.
Is it possible for me to build a form that can do Insert, Update and Delete using just one php form.
You can create one form, and with JS/jQuery (or any other lib) submit that form via Ajax depending on button clicked:
<form id="my-form">
...
<tr>
<td><label>Student ID:</label></td>
<td><input type="text" name="StuID" id="stu-id"></td>
<td><input type="submit" name="find" value="Find" onClick="sendPost()"></td>
</tr>
<tr>
<td><input type="button" name="add" value="Add" onClick="sendPost()"></td>
<td><input type="button" name="update" value="Update" onClick="sendPut()"></td>
<td><input type="button" name="delete" value="Delete" onClick="sendDelete()"></td>
</tr>
</form>
function sendFind() {
$.ajax({
url: 'example.com/my-action?StuID=' + $('#stu-id').val(),
method: 'GET',
success: function () {}
...
});
}
function sendPut() {
$.ajax({
url: 'example.com/my-action',
method: 'PUT',
dataType: 'json',
data: $("#my-form").serialize(),
success: function () {}
...
});
}
function sendDelete() {
$.ajax({
url: 'example.com/my-action',
method: 'DELETE',
dataType: 'json',
data: $("#my-form").serialize(),
success: function () {}
...
});
}
As you can see there even can be same URL and act differently depending on request type.
Its not possible though you can use $_REQUEST in php to get any posted data whether with POST or GET.
For your case you can name your input type submit with different names then check in your php
<?php
if(isset($_POST['insert'])){ //insert functionality }
if(isset($_POST['update'])){ //update functionality }
if(isset($_POST['delete'])){ //delete functionality }
?>
When I click Add More Button then appending the same row and when I submit the form then I getting the first value of the product_name and color_id input field.Where is the problem I didn't find that.
Here is the html code:
<table class="table table-striped table-bordered text-center table-responsive">
<thead class="text-dark">
<tr>
<th>Product Name</th>
<th>Color</th>
#foreach($size_infos as $sizee)
<th>{{$sizee->size_name}}</th>
#endforeach
<th>Add More</th>
</tr>
</thead>
<form action={{url('product-purchase-process')}}" method="POST" enctype="multipart/form-data">
#csrf
<tbody class="add_item">
<tr>
<td width="20%">
<input class="form-control input typeahead" type="text" name="product_name[]" id="product_name" placeholder="Product Name" multiple='multiple'>
</td>
<td width="14%">
<select class="form-control input" name="color_id[]">
<option value="">--Select Color--</option>
#foreach($color_infos as $color)
<option value="{{$color->color_id}}">{{$color->color_name}}</option>
#endforeach
</select>
</td>
#foreach($size_infos as $size)
<td>
<div id="inputDiv">
<input type="hidden" name="size_id[]" value="{{$size->size_id}}" multiple='multiple'>
<input style="width:70px" class="from-control" type="text" name="product_quantity[]" multiple='multiple'>
</div>
</td>
#endforeach
<td width="10%">
<button type="button" id="add_more" class="btn btn-success"><i class="fa fa-plus" aria-hidden="true"></i></button>
</td>
</tr>
<tr>
</tr>
</tbody>
Here is the jquery code:
<script type = "text/javascript" >
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(document).on('focus', "#product_name", function () {
$(this).autocomplete({
source: function (request, response) {
$.ajax({
url: "{{url('autocomplete')}}",
data: {
products: request.products
},
dataType: "json",
success: function (data) {
var resp = $.map(data, function (obj) {
// console.log(obj.product_name);
return obj.product_name;
});
response(resp);
}
});
},
minLength: 1
});
//color field and image field extend here
var htmlString = `<tr class="ree"><td width="20%"><input class="form-control input typeahead" type="text" name="product_name[]" id="product_name" placeholder="Product Name"></td><td width="14%"><select class="form-control input" name="color_id"><option value="">--Select Color--</option>#foreach($color_infos as $colorr)<option value="{{$colorr->color_id}}">{{$colorr->color_name}}</option>#endforeach</select></td>#foreach($size_infos as $sizeee)<td><div id="inputDiv"><input type="hidden" name="size_id[]" value="{{$sizeee->size_id}}"><input style="width:70px" class="from-control" type="text" name="product_quantity[]"></div></td>#endforeach<td width="10%"><button type="button" class="btn btn-danger btnRemove"><i class="fa fa-trash" aria-hidden="true"></i></button></td></tr>`;
$('#add_more').click(function () {
$('.add_item').append(htmlString); // end append
$('.ree .btnRemove').last().click(function () {
$(this).parent().last().remove();
}); // end click
}); // end click
}); </script>
I have a while loop which creates forms like:
<?php
$i = 1;
while($i<10){
?>
<form id="update">
<tr>
<th scope="row"><?php echo $i;?></th>
<td></td>
<td></td>
<td></td>
<td><input type="text" maxlength="5" class="input-xs valid" name="plus" value="" /></td>
<td><input type="submit" name="submit" class="btn btn-info btn-sm" value="Update" /></td>
<td><input class="input-sm slip" name="slip" value="" disabled /></td>
<td></td>
</tr>
</form>
<?php $i++; } ?>
I want to post the formdata of user-submitted form with jQuery AJAX.
your question is not clear but here is the answer
- if you are generating the forms on the basis of while loop, then you need to pas that $i in every where in the form
<?php
$i = 1;
while($i<10){
?>
<form id="update_<?php echo $i ?>">
<tr>
<th scope="row"><?php echo $i;?></th>
<td></td>
<td></td>
<td></td>
<td><input type="text" maxlength="5" class ="input-xs valid" id="plus_<?php echo $i?>" name="plus" value=""></td>
<td><input type="button" name="submit" class="btn btn-info btn-sm" value="Update" onclick="sub_form(<?php echo $i; ?>)"></td>
<td><input class="input-sm slip" id="slip_<?php echo $i?>" name="slip" value="" disabled/></td>
<td></td>
</tr>
</form>
<?php $i++; } ?>
AJAX
function sub_form(val){
var plus = document.getElementById('plus_'+val).value;
var slip = document.getElementById('slip_'+val).value;
$.ajax(
{
type:"post",
url: "your url here",
data:{ plus:plus, slip:slip},
success:function(response)
{
}
}
);
}
hope it will work for you
You should add a class in form HTML node as below:
<form class="anyclass" action="add your action where you want to post form">
And after this, you can submit form as below:
$(".anyclass").submit(function(e) {
e.preventDefault
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: $(this).serialize(),
success: function(data)
{
alert('form submitted herer');
}
});
Hope it helps you.
I have form with few inputs and two selects. When I select brand i want to see model options. Everything is working. But when i click submit, vehicle_model field is empty. Fields in $_POST are filled except vehicle_model field. I don't know why.
<div class="form-group">
<select class="form-control brand-select" name="brand" required="">
<option selected="true" value="1">MAN</option>
<option value="2">Volvo</option>
<option value="3">Renault</option>
<option value="4">DAF</option>
</select>
</div>
<div class="form-group" id="ajax_model">
<select class="form-control" name="vehicle_model" required="">
<option selected="" value="1">XS1</option>
<option value="2">XS2</option>
</select>
</div>
$(".brand-select").change(function() {
var id_brand = $(this).val();
var vehicle_type = <?php echo $type;?>;
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "vehicle/ajax_model",
data: {
'id_brand': id_brand,
'vehicle_type': vehicle_type
},
dataType: 'text',
success: function(data) {
$("#ajax_model").html(data);
}
});
});
My full code for form. AJAX is working - I get models after selected brand. But when I click "save" PHP doesn't see $vehicle_model. But only when i run AJAX. When I refresh page and don't change brand, everything is working.
<table id="tabela" class="table table-bordered table-striped">
<tbody>
<form action="http://192.168.0.200:9000/vehicle/update_information" method="post" accept-charset="utf-8">
<tr>
<td>Number:</td>
<td>
<div class="form-group"><input type="text" class="form-control" autocomplete="off" value="12345" name="number"></div>
</td>
</tr>
<tr>
<td>VIN:</td>
<td>
<div class="form-group"><input type="text" class="form-control" autocomplete="off" maxlength="17" minlength="17" value="12345678901234567" name="vin"></div>
</td>
</tr>
<tr>
<td>Brand:</td>
<td>
<div class="form-group">
<select class="form-control brand-select" name="brand" required>
<option selected="true" value='1'>MAN</option>
<option value='2'>Volvo</option>
<option value='3'>Renault</option>
<option value='4'>DAF</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Model:</td>
<td>
<div class="form-group" id="ajax_model">
<select class="form-control" name="vehicle_model" required>
<option selected value="1">XS1</option>
<option value="2">XS2</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Kilometers</td>
<td>
<div class="form-group"><input type="text" class="form-control" value="100 km" disabled></div>
</td>
</tr>
<tr>
<td>Comment:</td>
<td>
<textarea class="form-control" rows="5" name="comment" id="comment"></textarea>
<input type="hidden" name="id_vehicle" value="137" />
</td>
</tr>
<tr>
<td colspan="2"><button type='submit' class='btn btn-md btn-success' style="float:right;margin-top:10px;width:80px;">Save</button>
</td>
</tr>
</form>
</tbody>
</table>
Because you forgot to send vehicle_model
just try like this
<script>
$( ".brand-select" ).change(function() {
var id_brand = $(this).val();
var vehicle_model=$("select[name=vehicle_model]").val()
var vehicle_type = <?php echo $type;?>;
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>" + "vehicle/ajax_model",
data: {
'id_brand': id_brand,
'vehicle_type': vehicle_type,
'vehicle_model':vehicle_model},
dataType: 'text',
success: function(data){
$( "#ajax_model" ).html( data );
}
});
});
</script>
I am using ajax and jquery to submit the form. But it does not work. I am using following html form and jquery. To do this I want to use jQuery Ajax, but I don't know how to send the image with Ajax to PHP. Please Help me.
<form id="data" action="" method="post" enctype="multipart/form-data">
<table style="width:630px;float:left;padding:10px;padding-top:30px;">
<tr>
<td class="text_label">Name</td>
<td style="padding:10px;padding-right:20px;">:</td>
<td>
<input type="text" id="name" name="name" class="text_box" value="<?php echo $name;?>" />
</td>
</tr>
<tr>
<td class="text_label">Upload Image</td>
<td style="padding:10px;padding-right:20px;">:</td>
<td>
<input type="file" id="image" name="image" />
</td>
</tr>
<tr>
<td class="text_label"></td>
<td style="padding:10px;padding-right:20px;"></td>
<td>
<input type="button" value="Update" class="btn_upd" onclick="update_stdDetails();" />
</td>
</tr>
</table>
</form>
My jquery is
function update_stdDetails() {
var formData = new FormData($(this)[0]);
$.ajax({
url: 'ajax/update_stdDetails.php',
type: 'POST',
data: formData,
async: false,
success: function (data) {
alert(data)
},
cache: false,
contentType: false,
processData: false
});
}