Data insert & Delete works fine. However, the edit doesn't update the data. Instead it inserts a new one..
I have INSERT & UPDATE in a single file, made with if conditions:
<?php
include ("./backend/config/connection.php");
include ("./backend/config/function.php");
if (isset($_POST["traffic_operation"])) {
if (isset($_POST["traffic_operation"]) == "Add") {
$traffic_doc = "";
if ($_FILES["traffic_doc"]["name"] != "") {
$traffic_doc = upload_image();
}
$statement = $connection->prepare('INSERT INTO traffic_violations (
plateNumber,
carModel,
carColor,
violationType,
ownerGender,
violationDateTime,
violationLocation,
workingShift,
violationAction,
violationStatement,
cccEmployee
) VALUES (
:plate_number,
:car_model,
:car_color,
:violation_type,
:owner_gender,
:violation_date,
:violation_location,
:working_shift,
:violation_action,
:traffic_doc,
:ccc_employee
)
');
$result = $statement->execute([
":plate_number" => $_POST["plate_number"],
":car_model" => $_POST["car_model"],
":car_color" => $_POST["car_color"],
":violation_type" => $_POST["violation_type"],
":owner_gender" => $_POST["owner_gender"],
":violation_date" => $_POST["violation_date"],
":violation_location" => $_POST["violation_location"],
":working_shift" => $_POST["working_shift"],
":violation_action" => $_POST["violation_action"],
":traffic_doc" => $traffic_doc,
":ccc_employee" => $_POST["ccc_employee"],
]);
if (!empty($result)) {
echo 'Traffic Violation Added';
}
}
if ($_POST["traffic_operation"] == "Edit") {
$traffic_doc = "";
if ($_FILES["traffic_doc"]["name"] != "") {
$traffic_doc = upload_image();
}
$statement = $connection->prepare('UPDATE traffic_violations SET
plateNumber = :plate_number,
carModel = car_model,
carColor = car_color,
violationType = violation_type,
ownerGender = owner_gender,
violationDateTime = violation_date,
violationLocation = violation_location,
workingShift = working_shift,
violationAction = violation_action,
violationStatement = traffic_doc,
cccEmployee = ccc_employee,
WHERE id = :id');
$result = $statement->execute([
":id" => $_POST["violation_id"],
":plate_number" => $_POST["plate_number"],
":car_model" => $_POST["car_model"],
":car_color" => $_POST["car_color"],
":violation_type" => $_POST["violation_type"],
":owner_gender" => $_POST["owner_gender"],
":violation_date" => $_POST["violation_date"],
":violation_location" => $_POST["violation_location"],
":working_shift" => $_POST["working_shift"],
":violation_action" => $_POST["violation_action"],
":traffic_doc" => $traffic_doc,
":ccc_employee" => $_POST["ccc_employee"],
]);
if (!empty($result)) {
echo "Traffic Violation Updated";
}
}
}
?>
I also use Ajax:
$(document).ready(function() {
$("#add_btn").on('click', function() {
$("#traffic_violation_form")[0].reset();
$(".violation-title").text("Add New Violation");
$("#traffic_action").val("Add");
$("#traffic_operation").val("Add");
$("#traffic_doc").html('');
});
var dataTable = $('.violation_data').DataTable({
"processing": true,
"serverSide": true,
"order": [],
"ajax": {
url: "/traffic-fetch",
type: "POST"
},
"columnDefs": [
{
"target": [0, 3, 4],
"orderable": false
}
]
});
// For Inserting New Violation
$(document).on('submit', '#traffic_violation_form', function(e){
e.preventDefault();
var plateNumber = $("#plate_number").val();
var carModel = $("#car_model").val();
var carColor = $("#car_color").val();
var ownerGender = $("#owner_gender").val();
var violationType = $("#violation_type").val();
var violationLocation = $("#violation_location").val();
var workingShift = $("#working_shift").val();
var violationAction = $("#violation_action").val();
var violationStatement = $("#traffic_doc").val().split('.').pop().toLowerCase();
var cccEmployee = $("#ccc_employee").val();
if(violationStatement != '') {
if( $.inArray(violationStatement, ['jpg', 'jpeg', 'JPG', 'JPEG', 'png', 'PNG', 'webp', 'WEBP']) == -1 ) {
alert('Invalid file type.');
$("#traffic_doc").val();
return false;
}
}
if( plateNumber !='' && carModel !='' && carColor !='' && ownerGender !='' && violationType !='' && violationLocation !='' && workingShift !='' && violationAction !='' && cccEmployee !='') {
$.ajax({
url: "/traffic-insert",
method: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(data) {
$("#traffic_violation_form")[0].reset();
$("#trafficModal").modal('hide');
dataTable.ajax.reload();
}
});
}
else {
alert('Nothing should left empty!');
}
});
// For Updating Violation
$(document).on('click', '.update', function(){
var violation_id = $(this).attr("id");
$.ajax({
url:"/traffic-edit",
method:"POST",
data:{violation_id:violation_id},
dataType:"json",
success:function(data)
{
$("#trafficModal").modal('show');
$(".violation-title").text("Edit Violation");
$("#violation_id").val(violation_id);
$("#plate_number").val(data.plate_number);
$("#car_model").val(data.car_model);
$("#car_color").val(data.car_color);
$("#owner_gender").val(data.owner_gender);
$("#violation_type").val(data.violation_type);
$("#violation_location").val(data.violation_location);
$("#working_shift").val(data.working_shift);
$("#violation_action").val(data.violation_action);
$("#ccc_employee").val(data.ccc_employee);
$("#user_uploaded_image").html(data.violationStatement);
$("#traffic_action").val("Edit");
$("#traffic_operation").val("Edit");
}
})
});
$(document).on('click', '.delete', function(){
var violation_id = $(this).attr("id");
if(confirm("Are you sure you want to delete this?"))
{
$.ajax({
url:"/traffic-delete",
method:"POST",
data:{violation_id:violation_id},
success:function(data)
{
alert(data);
dataTable.ajax.reload();
}
});
}
else
{
return false;
}
});
});
And here is the HTML form:
<form name="traffic_violation_form" id="traffic_violation_form" action="/traffic-process" method="POST" enctype="multipart/form-data">
<div class="modal-body" id="violation-data">
<div class="form-row">
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="plate_number">Plate Number</label>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Plate #</span>
</div>
<input type="text" class="form-control" id="plate_number" name="plate_number" >
</div>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="car_model">Vehicle Model</label>
<div class="input-group">
<input type="text" class="form-control" id="car_model" name="car_model" >
</div>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="car_color">Vehicle Color</label>
<div class="input-group">
<input type="text" class="form-control" id="car_color" name="car_color" >
</div>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="owner_gender">Owner Gender</label>
<div class="input-group">
<select class="form-control" name="owner_gender" id="owner_gender" data-toggle="select" >
<option value="" disabled selected>Select Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="No driver">No Driver</option>
</select>
</div>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="violation_type">Violation Type</label>
<select data-toggle="select" class="form-control" name="violation_type" id="violation_type" >
<option value="" disabled selected>Select violation type</option>
<option value="Speeding">Speeding</option>
<option value="Drifting">Drifting</option>
<option value="Pass traffic light">Pass traffic light</option>
</select>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="violation_location">Violation Location</label>
<select class="form-control" name="violation_location" id="violation_location" data-toggle="select" >
<option value="" disabled selected>Select Location</option>
<option value="Baylasun">Baylasun</option>
<option value="Baylasun Hotel">Baylasun Hotel</option>
<option value="AL-Waha">AL-Waha</option>
<option value="Al-Morooj">Al-Morooj</option>
<option value="Royal Green">Royal Green</option>
<option value="Beach Towers">Beach Towers</option>
<option value="Emmar Building">Emmar Building</option>
<option value="Industrial Area (East)">Industrial Area (East)</option>
<option value="Industrial Area (West)">Industrial Area (West)</option>
<option value="Hejaz Gate">Hejaz Gate</option>
<option value="Gate 3">Gate 3</option>
<option value="Marina 1">Marina 1</option>
<option value="Marina 2">Marina 2</option>
<option value="Marina 3">Marina 3</option>
<option value="Tala Garden">Tala Garden</option>
<option value="AL-Shorooq">AL-Shorooq</option>
<option value="Yam Beach">Yam Beach</option>
<option value="Sales Center">Sales Center</option>
</select>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="violation_date">Violation Created At</label>
<input class="form-control" type="datetime-local" name="violation_date" id="violation_date" >
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="working_shift">Working Shift</label>
<select class="form-control" name="working_shift" id="working_shift" data-toggle="select" >
<option value="" disabled selected>Select Shift</option>
<option value="Morning">Morning (A)</option>
<option value="Evening">Evening (B)</option>
<option value="Night">Night (C)</option>
</select>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="traffic_doc">Violation Statement</label>
<input type="file" class="form-control" id="traffic_doc" name="traffic_doc" >
<span id="user_uploaded_image"></span>
</div>
</div>
<div class="col-md-6 mb-3">
<div class="form-group">
<label class="form-control-label" for="ccc_employee">CCC Employee</label>
<input type="text" class="form-control" id="ccc_employee" name="ccc_employee" >
</div>
</div>
<div class="col-md-12 mb-3">
<div class="form-group">
<label class="form-control-label" for="violation_action">Violation Action</label>
<textarea class="form-control" name="violation_action" id="violation_action" ></textarea>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<input type="hidden" name="violation_id" id="violation_id" />
<input type="hidden" name="traffic_operation" id="traffic_operation" />
<input type="submit" name="traffic_action" id="traffic_action" class="btn btn-primary" value="Add" />
</div>
</form>
The issue is in your condition that you are trying to compare with "Add"
The output of $_POST["traffic_operation"]) will be TRUE OR FALSE.
So replace the below line
if (isset($_POST["traffic_operation"]) == "Add")
with
if ( (isset($_POST["traffic_operation"]) AND ($_POST["traffic_operation"] == "Add") )
Related
I have module that you will transfer the qty from "warehouse from" to "warehouse to"(Warehouse From & Warehouse To these are my dropdown)
I want put some validation that you cannot longer choose the first selected warehouse coming from "warehouse from"
View
<div class="row">
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 input-padding-left">
<div class="form-group">
<label>Document Reference</label>
<input type="text" name="document_reference" class="form-control">
</div>
<div class="form-group">
<label>From:</label>
<select class="form-control warehouse" name="warehouse_from" required="required" id="warehouse_from" style="width: 100%;">
<option></option>
<option value="0">Unassigned Warehouse</option>
#if($warehouses)
#foreach($warehouses as $v => $warehouse)
<option value="{{ $warehouse->id }}">{{ $warehouse->name }}</option>
#endforeach
#endif
</select>
</div>
</div>
<hr>
<div class="col-xs-12 col-sm-6 col-md-6 col-lg-6 input-padding-right">
<div class="form-group">
<label>Posting Date</label>
<input type="text" name="posting_date" class="form-control dates">
</div>
<div class="form-group">
<label>To:</label>
<select class="form-control warehouse" name="warehouse_to" id="warehouse_to" required="required" style="width: 100%;">
<option></option>
#if($warehouses)
#foreach($warehouses as $v => $warehouse)
<option value="{{ $warehouse->id }}">{{ $warehouse->name }}</option>
#endforeach
#endif
</select>
</div>
</div>
Jquery
$('.warehouse').select2({
placeholder: "Select a Warehouse",
});
$(document).on('select2:select', '#warehouse_from', function(e){
// $('#warehouse_from ').on('change',function(){
//send ajax request
var id = $(this).val();
var val = $('#warehouse_from option:selected').text();
alert(val);
$(this).find('option').prop('disabled',false);
$(this).find('option[value='+val+']').prop('disabled',true);
getItemsByWarehouse(id);
e.preventDefault();
return false;
});
Question: Why my disabled didnt work?
You getting the text, not the value of the selected option element:
var val = $('#warehouse_from option:selected').text();
// ...
$(this).find('option[value='+val+']').prop('disabled',true);
It should be:
var val = $('#warehouse_from option:selected').val();
// ...
$(this).find('option[value='+val+']').prop('disabled',true);
My mistake is im disabling the value coming from warehouse_from not in the warehouse_to.
**Jquery**
$(document).on('select2:select', '#warehouse_from', function(e){
//send ajax request
var id = $(this).val();
var val = $('#warehouse_from option:selected').text();
alert(id);
$('select#warehouse_to>option[value="'+id+'"]').attr('disabled','disabled');
getItemsByWarehouse(id);
e.preventDefault();
return false;
});
This question already has answers here:
Stop form refreshing page on submit
(20 answers)
How can I prevent refresh of page when button inside form is clicked?
(16 answers)
Closed 4 years ago.
Im trying to insert data with ajax, but i got error :
Symfony \ Component \ HttpKernel \ Exception \
MethodNotAllowedHttpException
This is my form in add-gallery.blade.php:
<form method="post" action="" enctype="multipart/form-data" autocomplete="off" class="mt-4 mb-4 card p-4">
<div class="form-group">
<div class="row">
<div class="col-md-2 align-self-center">
<label for="gallery_name">Name</label>
</div>
<div class="col-md-6 align-self-center">
<input type="text" name="gallery_name" id="gallery_name" class="form-control" placeholder="Type Gallery Name" />
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 align-self-center">
<label for="category">Category</label>
</div>
<div class="col-md-3 align-self-center">
<select class="form-control custom-select" name="category" id="category">
<option value="">Select Category</option>
<option value="Home">Home</option>
<option value="Office">Office</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 align-self-center">
<label for="subcategory">Sub Category</label>
</div>
<div class="col-md-3 align-self-center">
<select class="form-control custom-select" name="subcategory" id="subcategory">
<option value="">Select Sub Category</option>
<option value="Interior">Interior</option>
<option value="Eksterior">Eksterior</option>
<option value="Decoration">Decoration</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 align-self-center">
<label for="subsubcategory">Subsub Category</label>
</div>
<div class="col-md-3 align-self-center">
<select class="form-control custom-select" name="subsubcategory" id="subsubcategory">
<option value="">Select Subsub Category</option>
<option value="Room">Room</option>
<option value="Bathroom">Bathroom</option>
<option value="Kitchen">Kitchen</option>
<option value="Terrace">Terrace</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2">
<label for="gallery_image">Image</label>
</div>
<div class="col-md-10">
<div class="fileinput fileinput-new" data-provides="fileinput">
<div class="fileinput-new thumbnail w-100" style="display: none;">
<img src="http://placehold.it/1186x800" />
</div>
<div id="toAnnotate" class="fileinput-preview fileinput-exists thumbnail w-100"></div>
<div>
<span class="btn btn-xs btn-success btn-file"><span class="fileinput-new">Select image</span><span class="fileinput-exists">Change</span><input type="file" name="gallery_image" id="gallery_image"></span>
Remove
</div>
</div>
<p><small><em>Image Size : 1186px (width), 800px (height)</em></small></p>
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-2 align-self-center"> </div>
<div class="col-md-10 align-self-center">
<button type="button" class="btn btn-secondary">Cancel</button>
<button type="submit" class="btn btn-success" id="save">Save</button>
</div>
</div>
</div>
</form>
And below is my ajax in same page add-gallery.blade.php:
<script type="text/javascript">
$(document).ready(function (e) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
//Save
$('#save').on('click', function () {
var gallery_name = $('#gallery_name').val();
var category = $('#category').val();
var subcategory = $('#subcategory').val();
var subsubcategory = $('#subsubcategory').val();
var gallery_image = $('#gallery_image').val();
var dataSubmit = $(this).serialize();
var top = top;
var left = left;
var file_data = $('#gallery_image').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url : "{{ url('galleries/store') }}",
dataType : 'text', // what to expect back from the server
cache : false,
contentType : false,
processData : false,
data : form_data,
type : 'post',
dataType : 'json',
success: function (response) {
console.log(response);
},
error: function (response) {
console.log(response);
}
});
});
});
</script>
This is my routes file web.php:
Route::post('galleries/store','Dashboard\GalleryController#store');
And this is my controller GalleryController.php:
public function store(Request $request){
if($request->hasFile('gallery_image')){
$fileImage = $request->file('gallery_image');
$fileImageExtension = $fileImage->extension();
$renameFileImage = 'ImageGalleries'.time().'.'.$fileImageExtension;
$pathFileImage = $fileImage->storeAs('public/galleries_documents/images_galleries', $renameFileImage); /images_articles
$galleries = new Gallery;
$points = new Point;
$galleries->name = $request->gallery_name;
$galleries->category = $request->category;
$galleries->sub_category = $request->subcategory;
$galleries->sub_subcategory = $request->subsubcategory;
$galleries->image = $renameFileImage;
$galleries->lang_id = session('lang_id');
$galleries->save();
$lastInsertId = $galleries->id;
for($i = 0; $i < count($request->node); $i++) {
$node[] = [
'node_position_top' => $request->node[$i],
'node_position_left' => $request->node[$i],
'id_gallery' => $lastInsertId,
];
$points->lang_id = session('lang_id');
}
Point::insert($node); //save to table
print_r($node[]);
exit();
}
}
I have issues with submitting a form through ajax. I am submitting the same form two times and I want to email for the same form. On the first submission, I want the name, email, contact information and on the second submission of the form I want the city related information about the user . The form is working fine but I get the mail only when the user submits the form on the second attempt. When a user submits the forms through ajax I did not get any email information about the user name and email etc. Also, i am using a google captcha in that form. the code is working fine just I am not receiving any email on the first submission of the form . Need help..!! Any help would be appreciated Thanks..!!
Here is my code :-
if(isset($_POST['contraform']) && $_POST['contraform']=='submited'){
$secret = "6Lf0MAoUAAAAAMWzxj-kbdy-u32onIYhZ0TdzpDc";
$response = $_POST['g-recaptcha-response'];
$remoteip = $_SERVER['REMOTE_ADDR'];
$url = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=$secret&response=$response&remoteip=$remoteip");
$result = json_decode($url, TRUE);
if ($result['success'] == 1) {
if(isset($_POST["source"])){
$source = $_POST["source"];
}
if(isset($_POST["uname"])){
$name = $_POST["uname"];
}
if(isset($_POST["uemail"])){
$email = $_POST["uemail"];
}
if(isset($_POST["uphonefull"])){
$phone = $_POST["uphonefull"];
}
if(isset($_POST["utreatments"])){
$treatment = $_POST["utreatments"];
}
if(isset($_POST["form_name"])){
$form_name = $_POST["form_name"];
}
if(isset($_POST["ucity"])){
$city = $_POST["ucity"];
}
if(isset($_POST["uhospital"])){
$hospital = $_POST["uhospital"];
}
if(isset($_POST["thanks"])){
$thanks = $_POST["thanks"];
}
header_contact_forms($source,$name,$email,$phone,$treatment,$form_name, $city,$hospital);
}
}
Here is my form code :-
<form name="contraform" id="contraform" method="post" action="<?php bloginfo("template_directory"); ?>/forms/process.php">
<input type="hidden" name="form_name" id="form_name" value="Header Contact Form" class="basicformname" >
<input type="hidden" value="<?php echo $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" name="source" id="source" />
<input type="hidden" value="submited" name="basicform"/>
<div id="sf1" class="frm">
<fieldset>
<!--<legend>Take a step for a Good health.</legend>-->
<div class="wor-alert"><p class="text-center fill-fields">Please Fill All This Fields*</p></div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon" id="basic-addon"><i class="abc-icon abc-user"></i></span>
<input type="text" placeholder="Name" id="uname" name="uname" class="form-control" autocomplete="off">
<span class="nameerr" id="unameerr"><?php echo #$_SESSION['unameerr'] ? $_SESSION['unameerr']:''; unset($_SESSION['unameerr']); ?></span>
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon" id="basic-addon"><i class="abc-icon abc-envelope"></i></span>
<input type="email" placeholder="Email" id="uemail" name="uemail" class="form-control" autocomplete="on">
<span class="emailerr" id="uemailerr"><?php echo #$_SESSION['uemailerr'] ? $_SESSION['uemailerr']:''; unset($_SESSION['uemailer']); ?></span>
</div>
</div>
<div class="form-group">
<input type="text" placeholder="Phone Number" id="uphone" name="uphone" class="uphone form-control" autocomplete="off">
<span class="phoneerr" id="uphoneerr"><?php echo #$_SESSION['uphoneerr'] ? $_SESSION['uphoneerr']:''; unset($_SESSION['uphoneerr']); ?></span>
<input type="hidden" class="uphonefull" name="uphonefull">
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon" id="basic-addon"><i class="abc-icon abc-user-md"></i></span>
<span class="plain-select">
<select name="utreatments" data-style="btn-primary" id="utreatments" class="form-control selectpicker">
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
<option value="value">value</option>
</select>
</span>
</div>
</div>
<div class="col-md-12 text-center">
<div class="head-captcha">
<div id="recaptcha3"></div>
<input type="hidden" class="hiddenRecaptcha required" name="bhiddenRecaptcha" id="bhiddenRecaptcha">
</div>
</div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class=" text-center">
<button class="btn open1" type="button" id="head-frm-btn">Next <span class="fa fa-arrow-right"></span></button>
</div>
</fieldset>
</div>
<div id="sf2" class="frm" style="display: none;">
<fieldset>
<!--<legend>What treatment are you looking for?</legend>-->
<div class="form-group">
<span class="plain-select">
<select name="ucity" id="ucity" class="form-control">
<option value="none">Select City</option>
<option value="Mumbai">Mumbai</option>
<option value="Pune">Pune</option>
<option value="Banglore">Banglore</option>
<option value="Nagpur">Nagpur</option>
<option value="Goa">Goa</option>
</select>
</span>
</div>
<div class="form-group">
<span class="plain-select">
<select name="uhospital" id="uhospital" class="form-control">
<option value="">Select Hospital</option>
<option value="Hospital One">Hospital One</option>
<option value="Hospital Two">Hospital Two</option>
<option value="Hospital Three">Hospital Three</option>
<option value="Hospital Four">Hospital Four</option>
<option value="Hospital Five">Hospital Five</option>
</select>
</span>
</div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class=" text-center">
<button class="btn back2" type="button"><span class="fa fa-arrow-left"></span> Back</button>
<button class="btn open2" type="button" id="head-frm-btn-two">Next <span class="fa fa-arrow-right"></span></button>
</div>
</fieldset>
</div>
<div id="sf3" class="frm" style="display: none;">
<fieldset>
<!--<legend>Almost done</legend>-->
<div class="waittext">
<p>Our customer care executive will get in contact with you soon. Please bear with us.</p>
</div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class=" text-center">
<button class="btn back3" type="button"><span class="fa fa-arrow-left"></span> Back</button>
<input class="btn open3" value="Submit" type="submit" name="head_form_submit">
</div>
</fieldset>
</div>
</form>
Here is the Ajax Form Submission Code :-
var eml = /^([A-Za-z0-9_\-\.])+\#([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
$("#head-frm-btn, #head_form_submit").click(function () {
$(".wor-alert").hide();
var source = $("#source").val();
var uname = $("#uname").val();
var uemail = $("#uemail").val();
var uphone = $("#uphone").val();
// var ucity = $("#ucity").val();
//var uhospital = $("#uhospital").val();
var utreatments = $("#utreatments").val();
var uphonefull = $(".uphonefull").val();
var form_name = $("#form_name").val();
var basicform = "submited";
// Returns successful data submission message when the entered information is stored in database.
var dataString = 'uname=' + uname + '&uemail=' + uemail + '&uphonefull=' + uphonefull +'&utreatments='+utreatments+'&basicform='+basicform+'&form_name ='+form_name + '&source=' + source;
if (uname == '' || uemail == '' || uphone == '' || eml.test($.trim(uemail)) == false) {
$(".wor-alert").stop().fadeIn('slow');
return false;
}else {
// AJAX Code To Submit Form.
$.ajax({
type: "POST",
url: "wp-content/themes/theme-name/forms/process.php",
data: dataString,
cache: false,
success: function (response) {
$('#response').html(response);
}
});
}
return false;
});
header_contact_froms function :-
function header_contact_forms($source,$name,$email,$phone,$treatment,$form_name, $city,$hospital){
include('mail.php');
if($city){include('thankyou.php');}
}
i don't know where to start. i have a dropdown list and onchange it will pass 2 values. from it i need to append form set base on setting (select query from database from the value i pass)
index.php
<div class="form-group">
<label for="add-name" class="col-sm-4 control-label">Staff</label>
<div class="col-sm-8">
<?php
$sqlEmpSelect = "select * from payroll_emp order by emp_name";
$qryEmpSelect = sqlsrv_query( $conn, $sqlEmpSelect );
?>
<select name="dpEmp" id="dpEmp" class="form-control">
<option>Sila Pilih</option>
<?php while( $rowAllow = sqlsrv_fetch_array( $qryEmpSelect, SQLSRV_FETCH_ASSOC) ) { ?>
<option value="<?=$rowAllow['emp_id']?>"><?=$rowAllow['emp_name']?></option>
<?php
}
sqlsrv_free_stmt($qryEmpSelect);
?>
</select>
</div>
</div>
<div class="form-group">
<label for="add-template" class="col-sm-4 control-label">Template</label>
<div class="col-sm-8">
<select name="dpTemp" id="dpTemp" class="form-control">
<option value="">Sila Pilih</option>
<?php
$sqlTemp = sprintf("select * from payroll_template order by template_name");
$qryTemp = mysql_query($sqlTemp) or die(mysql_error());
while ($resTemp = mysql_fetch_assoc($qryTemp)) {
?>
<option value="<?php echo $resTemp['template_id']; ?>"/><?php echo $resTemp['template_name']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div id="div-data" name="div-data"></div>
here the jquery i try to use it..
$('#div-data').hide();
$('#dpTemp').change(function(){
var empvalue = $('#dpEmp').val();
var tempvalue = $('#dpTemp').val();
if(tempvalue != ""){
$.ajax({
type:'get',
url:'kew8/htmlforms.php',
data:'empid=' + empvalue + '&tempid=' + tempvalue,
success:function(html){
$('#div-data').html(html);
}
});
} else{
$('#div-data').hide();
}
});
here i try to call the forms set..
htmlforms.php
<?php
$sqlselect = "bla bla bla";
$result = "";
if ($result[0]['seeting1'] == 1) {
?>
<div class="form-group">
<label for="add-template" class="col-sm-4 control-label">Template</label>
<div class="col-sm-8">
<select name="dpTemp" id="dpTemp" class="form-control">
<option value="">Sila Pilih</option>
</select>
</div>
</div>
<div class="form-group">
<label for="add-desc" class="col-sm-4 control-label">Keterangan</label>
<div class="col-sm-8">
<textarea id="txtDesc" name="txtDesc" class="form-control"></textarea>
</div>
</div>
<?php
}
if ($result[0]['seeting2'] == 2) {
?>
<div class="form-group">
<label for="add-template" class="col-sm-4 control-label">Template</label>
<div class="col-sm-8">
<select name="dpTemp" id="dpTemp" class="form-control">
<option value="">Sila Pilih</option>
</select>
</div>
</div>
<div class="form-group">
<label for="add-desc" class="col-sm-4 control-label">Keterangan</label>
<div class="col-sm-8">
<textarea id="txtDesc" name="txtDesc" class="form-control"></textarea>
</div>
</div>
<?php } ?>
and more setting
I have this html code.
<form class="" role="form">
<div class="col-lg-2">
<div class="form-group">
<label for="streams">Select Stream</label>
<select name="streams" id="streams" class="form-control">
<option value="">-- Select --</option>
<?php
while($streamRow = mysql_fetch_array($streamResult)) {
echo
"<option value=".$streamRow[0].">".$streamRow[1]."</option>";
}
?>
</select>
</div>
</div>
<div class="col-lg-2">
<div class="form-group">
<label for="branches">Select Branch</label>
<select name="branches" id="branches" class="form-control">
<option value="">-- Select --</option>
</select>
</div>
</div>
<div class="col-lg-2">
<div class="form-group">
<label for="batches">Select Batch</label>
<select name="batches" id="batches" class="form-control">
<option value="">-- Select --</option>
</select>
</div>
</div>
<div class="col-lg-2">
<div class="form-group divBefore">
<label for="divisionBefore">Div</label>
<select name="divisionBefore" id="divisionBefore" class="form-control">
<option value="">Sel</option>
</select>
</div>
<div class="form-group divAfter hide">
<label for="division">Div</label>
<select name="division" id="division" class="form-control">
<option value="">Sel</option>
<?php
$divisionResult = mysql_query("SELECT * FROM division");
while($divisionRow = mysql_fetch_array($divisionResult)) {
echo
"<option value=".$divisionRow[0].">".$divisionRow[1]."</option>";
}
?>
</select>
</div>
</div>
<div class="col-lg-2">
<div class="form-group semesterBefore">
<label for="semBefore">Sem</label>
<select name="semBefore" id="semBefore" class="form-control">
<option value="">Sel</option>
</select>
</div>
<div class="form-group semesterAfter hide">
<label for="sem">Sem</label>
<select name="sem" id="sem" class="form-control">
<option value="">Sel</option>
</select>
</div>
</div>
<div class="col-lg-2">
<div class="form-group subject">
<label for="subject">Select Subject</label>
<select name="subject" id="subject" class="form-control">
<option value="">-- Select --</option>
</select>
</div>
</div>
<!--<div class="col-lg-2" id="lecBefore">
<div class="form-group">
<label for="subject">Select Lecture</label>
<select name="lect" id="lect" class="form-control">
<option value="">-- Select --</option>
</select>
</div>
</div>
<div class="col-lg-2 hide" id="lecAfter">
<div class="form-group">
<label for="subject">Select Lecture</label>
<select name="lecture" id="lecture" class="form-control">
<option value="">-- Select --</option>
<option value="1">Lecture 1</option>
<option value="2">Lecture 2</option>
<option value="3">Lecture 3</option>
<option value="4">Lecture 4</option>
<option value="5">Lecture 5</option>
<option value="6">Lecture 6</option>
<option value="7">Lecture 7</option>
<option value="8">Lecture 8</option>
</select>
</div>
</div>-->
<div class="col-lg-2 hide" id="date">
<div class="form-group">
<label for="dateNow">Start Date</label> <br>
<div class="input-group date" id="avsDate">
<input type="text" class="form-control" name="avsDateTxt" id="avsDateTxt" readonly value="<?php echo date('d-m-Y');?>"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
</div>
<div class="col-lg-2 hide" id="date1">
<div class="form-group">
<label for="dateNow">End Date</label> <br>
<div class="input-group date" id="endDate">
<input type="text" class="form-control" name="endDateTxt" id="endDateTxt" readonly value="<?php echo date('d-m-Y');?>"><span class="input-group-addon"><i class="glyphicon glyphicon-th"></i></span>
</div>
</div>
</div>
</form>
and my jquery is.
$(document).ready(function() {
$('.sidebar-menu .attnd').addClass('active');
$('.sidebar-menu .attnd .genExcel').addClass('active');
$(".sidebar-menu .attnd").tree();
$('#streams').change(function() {
$('#branches').html("<option value=''>-- Select --</option>");
$('#batches').html("<option value=''>-- Select --</option>");
$('.divAfter').hide();
$('.divBefore').show();
$('.semesterAfter').hide();
$('.semesterBefore').show();
$('#date').hide();
$('#date1').hide();
$('#lecAfter').hide();
$('#lecBefore').show();
$('#studManip').html('');
if($(this).val() != '')
$.streamSelection($(this).val());
});
$('#branches').change(function() {
$('#batches').html("<option value=''>-- Select --</option>");
$('.divAfter').hide();
$('.divBefore').show();
$('.semesterAfter').hide();
$('.semesterBefore').show();
$('#date').hide();
$('#date1').hide();
$('#lecAfter').hide();
$('#lecBefore').show();
$('#studManip').html('');
if($(this).val() != '')
$.branchSelection($(this).val());
});
$('#batches').change(function() {
$('.divAfter').hide();
$('.divBefore').show();
$('.semesterAfter').hide();
$('.semesterBefore').show();
$('#date').hide();
$('#date1').hide();
$('#lecAfter').hide();
$('#lecBefore').show();
$('#studManip').html('');
if($(this).val() != '') {
$.listSemester($(this).val());
$('.divBefore').hide();
$('#division').val('');
$('.divAfter').show();
}
});
$('#division').change(function() {
$('.studList').hide();
$('.semesterAfter').hide();
$('.semesterBefore').show();
$('#date').hide();
$('#date1').hide();
$('#lecAfter').hide();
$('#lecBefore').show();
$('#studManip').html('');
if($(this).val() != '') {
$('.semesterBefore').hide();
$('#sem').val('');
$('.semesterAfter').show();
}
});
$('#sem').change(function() {
$('#date').hide();
$('#date1').hide();
$('#lecAfter').hide();
$('#lecBefore').show();
$('#studManip').html('');
if($(this).val() != '')
$.searchSubject();
});
$('#subject').change(function() {
if($(this).val() != '') {
$.when($('#date').show())
.then($('#date1').show())
.then($('.btnExcel').show());
}
});
/*$('#lecture').change(function() {
$.when($('#date').hide())
.then($('#studManip').html(''));
if($(this).val() != '') {
$('#date').show();
$.when($.searchStudent())
.then($('#studManip').show());
}
});*/
$('#avsDate').datepicker({
format: "dd-mm-yyyy",
startDate: "01-01-2012",
endDate: '<?php echo date('d-m-Y')?>',
todayBtn: "linked",
autoclose: true,
todayHighlight: true,
});
$('#endDate').datepicker({
format: "dd-mm-yyyy",
startDate: "01-01-2012",
endDate: '<?php echo date('d-m-Y')?>',
todayBtn: "linked",
autoclose: true,
todayHighlight: true,
});
$('#avsDate').datepicker().on('changeDate', function(e) {
$.when($('.btnExcel').attr('href', 'studExcel.php?streamId='+$('#streams').val()+'&branchId='+$('#branches').val()+'&batchId='+$('#batches').val()+'&divisionId='+$('#division').val()+'&semId='+$('#sem').val()+'&sDate='+$('#advDatetxt').val()+'&eDate='+$('#endDatetxt').val()))
.then($('.btnExcel').show());
});
$('#endDate').change(function() {
$.when($('.btnExcel').attr('href', 'studExcel.php?streamId='+$('#streams').val()+'&branchId='+$('#branches').val()+'&batchId='+$('#batches').val()+'&divisionId='+$('#division').val()+'&semId='+$('#sem').val()+'&sDate='+$('#advDatetxt').val()+'&eDate='+$('#endDatetxt').val()))
.then($('.btnExcel').show());
});
/*var date = new Date();
$('#avsDate').datepicker().on('changeDate', function(e) {
$('#studManip').html('');
if(weekday[$(this).datepicker('getDate').getUTCDay()] != 'Sunday'){
$.when($.searchStudent())
.then($('#studManip').show());
} else
alert('Today is Sunday');
});*/
});
$.streamSelection = function(selStreamId) {
$.ajax({
url:"../student/searchBranch.php",
data:{
streamId:selStreamId,
},
success: function(data) {
$('#branches').html(data);
},
error: function(error) {
alert(error);
}
});
}
$.branchSelection = function(selBranchId) {
$.ajax({
url:"../student/searchBatch.php",
data:{
branchId:selBranchId,
},
success: function(data) {
$('#batches').html(data);
},
error: function(error) {
alert(error);
}
});
}
$.listSemester = function(selStreamId) {
$.ajax({
url:"../student/searchStream.php",
data:{
streamId:selStreamId,
},
success: function(data) {
$('#sem').html(data);
},
error: function(error) {
alert(error);
}
});
}
$.searchSubject = function() {
$.ajax({
url:"searchSubject.php",
data:{
streamId : $('#streams').val(),
branchId : $('#branches').val(),
semId : $('#sem').val(),
},
success: function(data) {
$('#subject').html(data);
},
error: function(error) {
alert(error);
}
});
}
every thing is working fine but when I change advDatetxt or endDatetxt jquery won't sending value with query string and describe as indefined. When I put cursor on excel button it will display left bottom corner as.
I think problem is only spell mistakes
<input type="text" class="form-control" name="avsDateTxt" id="avsDateTxt" readonly value="<?php echo date('d-m-Y');?>">
sDate='+$('#advDatetxt').val()
Here spell mistake in id value, change it as
sDate='+$('#avsDatetxt').val()
next one :
<input type="text" class="form-control" name="endDateTxt" id="endDateTxt" readonly value="<?php echo date('d-m-Y');?>">
eDate='+$('#endDatetxt').val()
Here also spell mistake, change it as
eDate='+$('#endDateTxt').val()
Some of your IDs don't match with the selectors.
See this
id="avsDateTxt"
against
$('#advDatetxt')