I'm currently creating a page where you can fill in damage claims about damaged cars/goods. You have 3 options (driver/subcontractor/personel) and JQuery is used to show/hide different textboxes according to the selected option.
Here's where it gets tricky. Everything works great until I submit the form. When I do it fires the changeVehicle JQuery-function again and reloads the original value in licensePlate again, even after I altered it in the form. The result being that I get the old variable for my license plate.
Does anyone have an idea why it refires?
My code:
<?php
...
<form id="form" class="form-horizontal" method="post" action="<?php echo $url?>&action=edit<?php echo $edit?>" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label" for="filenr"><?php echo $lng->show("claim_file_nr")?></label>
<div class="controls">
<input type="text" id="filenr" name="filenr" value="<?php echo $file_nr?>" disabled>
<input type="hidden" id="file_nr" name="file_nr" value="<?php echo $file_nr?>" />
</div>
</div>
<div class="control-group">
<label class="control-label" for="damage_type"><?php echo $lng->show("claim_damage_type")?>*</label>
<div class="controls">
<select id="damage_type" name="damage_type" <?php if ($par["id"] != 0) { echo "disabled"; } ?>>
<option value="0" <?php if ($damage_type == 0) echo "selected" ?>><?php echo $lng->show("claim_type_vehicle") ?></option>"
<option value="1" <?php if ($damage_type == 1) echo "selected" ?>><?php echo $lng->show("claim_type_goods") ?></option>"
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="date_damage"><?php echo $lng->show("claim_date_damage"); ?>*</label>
<div class="controls">
<div class="input-append">
<input class="input-small" type="text" id="date_damage" name="date_damage" data-date-format="dd-mm-yyyy" placeholder="dd-mm-yyyy"
value="<?php echo $cfunc->convertDateFromDB(substr($date_damage, 0, 10)) ?>" required>
<span class="add-on"><i class="icon-calendar"></i></span>
</div>
</div>
</div>
<div class="control-group">
<label class="control-label" for="description"><?php echo $lng->show("claim_description")?>*</label>
<div class="controls">
<textarea class="input-xxlarge" rows="4" id="description" name="description" required><?php echo $description;?></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label" for="choice"><?php echo $lng->show("claim_choice")?>*</label>
<div class="controls controls-row">
<select id="choice" name="choice" onchange="changeChoice();">
<option value="1" <?php if (isset($driver)&& $driver != 0) echo "selected" ?>><?php echo $lng->show("claim_driver") ?></option>"
<option value="2" <?php if (isset($subcontractor)&& $subcontractor != 0) echo "selected" ?>><?php echo $lng->show("claim_subcontractor") ?></option>"
<option value="3" <?php if ($personel != "") echo "selected" ?>><?php echo $lng->show("claim_personel") ?></option>"
</select>
</div>
</div>
<div id="driver-container" class="control-group">
<label class="control-label" for="driver"><?php echo $lng->show("claim_driver")?>*</label>
<div class="controls controls-row">
<select id="driver" name="driver">
<?php
$result = $db->q("SELECT * FROM ERP_drivers");
foreach ($result as $a) {
if ($driver == $a["driver_id"]) {
echo "<option value=".$a["driver_id"]." selected>".$a["driver_name"]."</option>";
}else{
echo "<option value=".$a["driver_id"].">".$a["driver_name"]."</option>";
}
}
?>
</select>
</div>
</div>
<div id="subcontractor-container" class="control-group">
<label class="control-label" for="subcontractor"><?php echo $lng->show("claim_subcontractor")?>*</label>
<div class="controls controls-row">
<select id="subcontractor" name="subcontractor">
<?php
$subcontractors = $db->q("SELECT r.relatie_id, r.relatie_naam
FROM relaties AS r INNER JOIN relatie_lijsten AS l
ON r.relatie_id = l.relatie_lijst_relatie_id
WHERE l.relatie_lijst_relatieslijst_id = 23");
foreach($subcontractors as $s){
if ($subcontractor == $s["relatie_id"]) {
echo "<option value=\"".$s["relatie_id"]."\" selected>".$s["relatie_naam"]."</option>";
}else{
echo "<option value=\"".$s["relatie_id"]."\">".$s["relatie_naam"]."</option>";
}
}
?>
</select>
</div>
</div>
<div id="personel-container" class="control-group">
<label class="control-label" for="personel"><?php echo $lng->show("claim_personel")?>*</label>
<div class="controls controls-row">
<select id="personel" name="personel">
<?php
$personelList = $db->q("SELECT * FROM `erp_gebruiker` WHERE `actief` =1");
foreach($personelList as $p){
if ($personel == $p["gebruiker_id"]) {
echo "<option value=\"".$p["gebruiker_id"]."\" selected>".$p["naam"]."</option>";
}else{
echo "<option value=\"".$p["gebruiker_id"]."\">".$p["naam"]."</option>";
}
}
?>
</select>
</div>
</div>
<div id="vehicle-container" class="control-group">
<label class="control-label" for="vehicle"><?php echo $lng->show("claim_choice_vehicle")?>*</label>
<div class="controls controls-row">
<select id="vehicle" name="vehicle" onchange="changeVehicle();">
<?php
$result = $db->q("SELECT * FROM ERP_vehicles");
foreach ($result as $v) {
if ($vehicle == $v["vehicle_id"]) {
echo "<option value=".$v["vehicle_id"]." selected>".$v["vehicle_name"]."</option>";
}else{
echo "<option value=".$v["vehicle_id"].">".$v["vehicle_name"]."</option>";
}
}
?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="license_plate"><?php echo $lng->show("claim_license_plate")?></label>
<div class="controls">
<input type="text" id="license_plate" name="license_plate" value="<?php echo $license_plate; ?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="faulty"><?php echo $lng->show("claim_faulty")?></label>
<div class="controls controls-row">
<select id="faulty" name="faulty">
<option value="0" <?php if ($faulty == 0) echo "selected"; ?>><?php echo $clng->show("no")?></option>";
<option value="1" <?php if ($faulty == 1) echo "selected"; ?>><?php echo $clng->show("yes")?></option>";
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="file_insurance"><?php echo $lng->show("claim_insurance_nr")?></label>
<div class="controls">
<input type="text" id="file_insurance" name="file_insurance" value="<?php echo $file_insurance?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="damage_amount"><?php echo $lng->show("claim_damage_amount")?></label>
<div class="controls">
<input type="number" step="0.01" id="damage_amount" name="damage_amount" value="<?php echo $damage_amount?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="exemption"><?php echo $lng->show("claim_exemption")?></label>
<div class="controls">
<input type="number" step="0.01" id="exemption" name="exemption" value="<?php echo $exemption?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="amount_payed"><?php echo $lng->show("claim_amount_payed")?></label>
<div class="controls">
<input type="number" step="0.01" id="amount_payed" name="amount_payed" value="<?php echo $amount_payed?>">
</div>
</div>
<div class="control-group">
<label class="control-label" for="status"><?php echo $lng->show("claim_status")?></label>
<div id="choice" class="controls">
<select id="status" name="status">
<option value="1" <?php if ($status == 1) echo "selected"; ?>><?php echo $lng->show("claim_status_handling")?></option>";
<option value="2" <?php if ($status == 2) echo "selected"; ?>><?php echo $lng->show("claim_status_handled")?></option>";
</select>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary"><?php echo $knop?></button>
<button type="button" class="btn" onclick="javascript:location.href='<?php echo $url?>'"><?php echo $clng->show("cancel")?></button>
</div>
</form>
<script>
$(function () {
$("input,select,textarea").not("[type=submit]").jqBootstrapValidation();
changeChoice();
// alert("blablabla");
});
$("#date_damage").datepicker({format:'dd-mm-yyyy'});
function changeChoice() {
var c = $("#choice :selected").val();
if (c == "1") {
$("#driver-container").show();
$("#subcontractor-container").hide();
$("#personel-container").hide();
} else if (c == "2") {
$("#driver-container").hide();
$("#subcontractor-container").show();
$("#personel-container").hide();
} else {
$("#driver-container").hide();
$("#subcontractor-container").hide();
$("#personel-container").show();
}
changeVehicle()
}
function changeVehicle() {
var choice = $("#choice :selected").val();
var vehiclePlate = $("#vehicle :selected").val();
var licensePlate = '<?php if ($par["id"] == 0 ) { echo ""; } else { echo $license_plate; }?>'
if (choice == "1" || choice == "3") {
$("#vehicle-container").show();
$("#license_plate").prop('disabled', true);
showLicense(vehiclePlate);
$("#license_plate").val(data[0]);
} else {
$("#vehicle-container").hide();
$("#license_plate").prop('disabled', false);
//$("#license_plate").val(licensePlate);
}
}
function showLicense(plate) {
$.ajax({
type: 'POST',
url: 'index.php?page=claims&ajax=getplate',
dataType: 'json',
data: { plate: plate },
success: function(data) {
$("#license_plate").val(data[0]);
}
});
}
</script>
Found it. It seemds that some validation-code is the bad guy. Everything works fine when I put this in comment:
<script>
$(function () {
//$("input,select,textarea").not("[type=submit]").jqBootstrapValidation();
changeChoice();
});
...
</script>
I don't really have an idea why, I'm still pretty new with this JavaScript/JQuery stuff, but at least I can find a workaround for the validation that line provided.
Related
When I click on update, a page is only getting refreshed, values are not updated. I have 4 tables in database, namely -> stud,country_master_academic,master_state, master_city. In a console, values are not showing when I click on update button.
my update.php page
<div class="container" style="width:700px;height:1100px;margin-top:10%;box-shadow:4px 3px 3px 3px grey;margin-left:25%;background-color:#eaf2fa;padding:3%;">
<h4 style="font-weight:bold;"><span class="glyphicon glyphicon-edit"></span>Update Student</h4>
<div class="form-group">
<label for="photo"></label>
<?php
$img = "images/".trim($vrow["photo"]);
echo '<img src='.$img.' id="resultedPhoto" class="image" style="margin-left:75%;margin-top:2%;width:120px;height:120px;border:2px solid #bbbbbb;border-radius:10px;">';
?><br/>
<input type="file" name="upphoto" id="upphoto" style="margin-left:70%;" required />
</div>
<form class="form-horizontal" name="form1" id="form1" method="post" action="<?php $_PHP_SELF?>" enctype="multipart/form-data">
<div class="form-group">
<label for="no"><span class="glyphicon glyphicon-lock"></span><b> Student No: </b></label>
<input type="text" class="form-control" name="upno" id="upno" disabled value="<?php echo $vrow['stud_no'];?>" required />
</div>
<div class="form-group">
<label for="name"><span class="glyphicon glyphicon-user"></span><b> Student Name: </b></label>
<input type="text" class="form-control" name="upname" id="upname" value="<?php echo $vrow['stud_name'];?>" required pattern="[a-zA-Z]{3,}" title="Name should only contain letters and atleast 3 letters"/>
</div>
<div class="form-group">
<label for="no"><span class="glyphicon glyphicon-phone"></span><b> Mobile No: </b></label>
<input type="text" class="form-control" value="<?php echo $vrow['mobile']; ?>" name="upmob_no" required id="upmob_no" pattern="[0-9]{10}" title="Mobile number should be of 10 digits"/>
</div>
<div class="form-group">
<label for="dob"><span class="glyphicon glyphicon-calendar"></span><b> Birth Date: </b></label>
<input type="date" required class="form-control" value="<?php echo $vrow['dob'];?>" name="updob" id="updob" />
</div>
<div class="form-group">
<label for="add"><span class="glyphicon glyphicon-map-marker"></span><b> Address: </b></label>
<textarea rows="4" cols="33" class="form-control" name="upadd" id="upadd" required><?php echo $vrow['address'];?></textarea>
</div>
<div class="form-group">
<label for="gen"><b> Gender: </b></label>
<input type="radio" name="gender" id="genderMale" value="M"<?php echo ($vrow['gender']=='M')?'checked':' ' ?> required="required">Male
<input type="radio" name="gender" id="genderFemale" value="F"<?php echo ($vrow['gender']=='F')?'checked':' ' ?> required="required">Female
</div>
<div class="form-group">
<label for="cntry"><span class="glyphicon glyphicon-map-marker"></span><b> Country: </b></label>
<select required name="upcountry" id="upcountry" class="form-control">
<option value="">Select</option>
<?php
$country="SELECT * from country_master_academic";
$res= $conn->query($country);
if($res->num_rows>0){
while($row=$res->fetch_assoc()){
if($row["country_name"]==$vcountry or $vrow['country'] == $row["country_code"] )
{
echo '<option value='.$row["country_code"].' selected>'.$row["country_name"].'</option>';
}
else
{
echo '<option value='.$row["country_code"].'>'.$row["country_name"].'</option>';
}
}
}
?>
</select>
</div>
<div class="form-group">
<label for="state"><span class="glyphicon glyphicon-map-marker"></span><b> State: </b></label>
<select required name="upstate" id="upstate" class="form-control">
<option value="">Select</option>
<?php
$state="SELECT * from master_state";
$res= $conn->query($state);
if($res->num_rows>0){
while($row=$res->fetch_assoc()){
if($row["state_name"]==$vstate or $vrow['state'] == $row["state_code"] )
{
echo '<option value='.$row["state_code"].' selected>'.$row["state_name"].'</option>';
}
else
{
echo '<option value='.$row["state_code"].'>'.$row["state_name"].'</option>';
}
}
}
?>
</select>
</div>
<div class="form-group">
<label for="city"><span class="glyphicon glyphicon-map-marker"></span><b> City: </b></label>
<select required name="upcity" id="upcity" class="form-control">
<option value="">Select</option>
<?php
$city="SELECT * from master_city";
$res= $conn->query($city);
if($res->num_rows>0){
while($row=$res->fetch_assoc()){
if($row["city_name"]==$vcity or $vrow['city'] == $row["city_code"] )
{
echo '<option value='.$row["city_code"].' selected>'.$row["city_name"].'</option>';
}
else
{
echo '<option value='.$row["city_code"].'>'.$row["city_name"].'</option>';
}
}
}
?>
</select>
</div>
<br/>
<div class="form-group">
<button type="submit" name="update" id="update" style="font-weight:bold;" class="btn btn-primary">Update</button>
</div>
</form>
</div>
upresult.php page
<?php
include("connection.php");
$no=trim($_POST['upno']);
$name=trim($_POST['upname']);
$mob=trim($_POST['upmob_no']);
$dob=trim($_POST['updob']);
$add=trim($_POST['upadd']);
$photo=trim($_FILES['upphoto']['name']);
$gen=trim($_POST['gender']);
$cn=trim($_POST['upcountry']);
$st=trim($_POST['upstate']);
$ct=trim($_POST['upcity']);
$qry="update stud set stud_name='".$name."',mobile='".$mob."',dob='".$dob."',address='".$add."',gender='".$gen."',country='".$cn."',state='".$st."',city='".$ct."' where stud_no='".$no."'";
$data=mysqli_query($conn,$qry);
if($data)
{
echo '<script language="javascript">';
echo 'alert("Updated Successfully")';
echo '</script>';
}
else {
echo '<script language="javascript">';
echo 'alert("Cannot update record")';
echo '</script>';
}
?>
jquery
$(document).ready(function(){
$("#form1").submit(function(event){
event.preventDefault();
var formData = new FormData(this);
$.ajax({
url:"upresult.php",
type:"POST",
data:{formData:formData},
async:true,
success:function(data) {
alert(data);
},
cache:false,
contentType:false,
processData:false
});
});
});
Thank you in advance.
Don't use the same name
data:{stud_no:stud_no}, //here change the name of vbl or value
data:{
formData:formData, //here change the name of vbl or value
stud_no:stud_no, //here change the name of vbl or value
}
How do I get last month salary, if last month salary was negative then I want to subtract last month negative salary from current month payment? like in pic, mar salary is-32000 so when I pay for April I want to subtract -32000 from April payment
<form role="form" enctype="multipart/form-data" action="<?php echo base_url(); ?>admin/payroll/get_payment/<?php
if (!empty($check_salary_payment->salary_payment_id)) {
echo $check_salary_payment->salary_payment_id;
}
?>" method="post" class="form-horizontal form-groups-bordered">
<div class="col-sm-3" data-spy="scroll" data-offset="0">
<div class="row">
<div class="panel panel-primary fees_payment">
<!-- Default panel contents -->
<div class="panel-heading" >
<div class="panel-title">
<strong>Payment For <?php echo date('F,Y', strtotime($payment_date)) ?></strong>
</div>
</div>
<div class="panel-body">
<div class="">
<label class="control-label" >Gross Salary </label>
<input type="text" name="house_rent_allowance" disabled value="<?php
echo $gross = $emp_salary_info->basic_salary + $emp_salary_info->house_rent_allowance + $emp_salary_info->medical_allowance + $emp_salary_info->special_allowance + $emp_salary_info->fuel_allowance + $emp_salary_info->phone_bill_allowance + $emp_salary_info->other_allowance;
?>" class="salary form-control">
</div>
<div class="">
<label class="control-label" >Total Deduction </label>
<input type="text" name="other_allowance" disabled value="<?php
echo $deduction = $emp_salary_info->tax_deduction + $emp_salary_info->provident_fund + $emp_salary_info->other_deduction;
?>" class="salary form-control">
</div>
<div class="">
<?php
$yourDate = date("Y-m", strtotime($payment_date. " -1 months")); // substract 1 month from that date and converting it into timestamp
echo $yourDate;
?>
<?php
if (!empty($payment_history)): foreach ($payment_history as $v_payment_history) :
?>
<?php
if ((date('F-Y', strtotime($v_payment_history->payment_fo_month == $yourDate ))) && ($v_payment_history->payment_amount < 0 ))
{
echo $negative_payment = $v_payment_history->payment_amount;
} ?>
<?php endforeach; ?>
<?php endif; ?>
</div>
<div class="">
<label class="control-label" >Net Salary </label>
<input type="text" id="net_salary" name="other_allowance" disabled value="<?php
if (isset($_POST['security_deposit'])) {
echo $net_salary = $emp_salary_info->basic_salary / 2;
}
else {
echo $net_salary = $gross - $deduction;
}
?>" class="salary form-control">
</div>
<?php if (isset($_POST['security_deposit'])) : ?>
<input type="hidden" name="security_deposit" id="security_deposit" value="<?php echo $net_salary = $emp_salary_info->basic_salary / 2; ?>" class="salary form-control">
<?php endif; ?>
<?php if (!empty($emp_salary_info->security_deposit)): ?>
<div class="">
<label class="control-label" >Security Deposited </label>
<input type="text" id="security_deposit1" name="security_deposit1" disabled value="<?php
echo $security = $emp_salary_info->security_deposit;
?>" class="salary form-control">
</div>
<?php endif; ?>
<?php if (!empty($award_info)): foreach ($award_info as $v_award_info) : ?>
<?php if (!empty($v_award_info->award_amount)): ?>
<div class="">
<label class="control-label" > Advance Salary <small>( <?php echo $v_award_info->award_name; ?> )</small> </label>
<input type="text" name="award_amount" id="award_amount" disabled value="<?php echo $v_award_info->award_amount; ?>" class="salary form-control">
<input type="hidden" name="award[]" value="<?php echo $v_award_info->award_amount; ?>" class="salary form-control">
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<div class="">
<label class="control-label" >Incentive</label>
<input type="text" name="incentive" id="incentive" value="<?php
if (!empty($check_salary_payment->incentive)) {
echo $check_salary_payment->incentive;
}
?>" class="salary form-control">
</div>
<div class="">
<label class="control-label" >Fine Deduction </label>
<input type="text" name="fine_deduction" id="fine_deduction" value="<?php
if (!empty($check_salary_payment->fine_deduction)) {
echo $check_salary_payment->fine_deduction;
}
?>" class="salary form-control">
</div>
<div class="">
<label class="control-label" ><strong>Payment Amount </strong></label>
<input type="text" name="payment_amount" id="payment_amount" value="<?php echo $net_salary; ?>" class="salary form-control">
</div>
<!-- Hidden Employee Id -->
<input type="hidden" id="employee_id" name="employee_id" value="<?php echo $emp_salary_info->employee_id; ?>" class="salary form-control">
<input type="hidden" name="payment_for_month" value="<?php
if (!empty($payment_date)) {
echo $payment_date;
}
?>" class="salary form-control">
<div class=""><!-- Payment Type -->
<label class="control-label" >Payment Type <span class="required"> *</span></label>
<select name="payment_type" class="form-control col-sm-5" onchange="get_payment_value(this.value)" >
<option value="" >Select Payment Type...</option>
<option value="Cash Payment" <?php
if (!empty($check_salary_payment->payment_type)) {
echo $check_salary_payment->payment_type == 'Cash Payment' ? 'selected' : '';
}
?>>Cash Payment</option>
<option value="Cheque Payment" <?php
if (!empty($check_salary_payment->payment_type)) {
echo $check_salary_payment->payment_type == 'Cheque Payment' ? 'selected' : '';
}
?>>Cheque Payment</option>
<option value="Bank Account" <?php
if (!empty($check_salary_payment->payment_type)) {
echo $check_salary_payment->payment_type == 'Bank Account' ? 'selected' : '';
}
?>>Bank Account</option>
</select>
</div><!-- Payment Type -->
<div class="">
<label class="control-label" >Comments </label>
<input type="text" name="comments" value="<?php
if (!empty($check_salary_payment->comments)) {
echo $check_salary_payment->comments;
}
?>" class="salary form-control">
</div>
<div class="form-group margin">
<div class="col-sm-5">
<button type="submit" name="sbtn" value="1" class="btn btn-primary btn-block">Save</button>
</div>
</div>
</div>
</div>
</div>
</div><!--************ Fees payment End ***********-->
</form>
I have tried this code, but this code show negative salary every time, I want to get negative salary only the next month. like in the image if negatively is in March then I want to show it only when I give salary for April. but this code show even when I select may June or any month
<div class="">
<?php
$yourDate = date("Y-m", strtotime($payment_date . " -1 months")); // substract 1 month from that date and converting it into timestamp
echo $yourDate;
?>
<?php if (!empty($payment_history)): foreach ($payment_history as $v_payment_history) : ?>
<?php
if ((date('F-Y', strtotime($v_payment_history->payment_fo_month == $yourDate))) && ($v_payment_history->payment_amount < 0 )) {
echo $negative_payment = $v_payment_history->payment_amount;
}
?>
<?php endforeach; ?>
<?php endif; ?>
</div>
I'm attempting my hand at ajax which i'm not the greatest at, my code for the page:
<?php
include('includes/db_connection.php');
include('includes/sessions.php');
include('includes/functions.php');
include('includes/header.php');
include('includes/navbar-logged.php');
require_once('api-sape.php');
// init sape
$sape = new SapeApi();
$userId = $sape->login(SAPE_USER, SAPE_PASS);
?>
<style type="text/css">
.modal-loading {
top: 0;
left: 0;
position: fixed;
z-index: 999;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.1);
display: none;
}
.modal-loading .loading {
width: 64px;
height: 64px;
margin: 200px auto;
}
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<div class="modal-loading"><div class="loading"><img src="http://wz.sera5902.myjino.ru/loading.gif"></div></div>
<?php
// isset
if (isset($_POST['search'])) {
// show var_dump
if ($member == SAPE_USER) { showPre($_POST); }
// try...
try
{
// vars
$sapeURLID = $_POST['url_id'];
$sapeDepth = $_POST['domain_level'];
$sapeInInG = $_POST['indexed_in_google'];
$sapeOrder = $_POST['order'];
$sapePLeve = $_POST['page_level'];
$sapeSdays = $_POST['search_days'];
$sapeKwdos = $_POST['keyword'];
$sapeKwpla = $_POST['keyword_placement'];
$sapeSdmoz = $_POST['site_in_dmoz'];
$sapeExtLi = $_POST['external_links'];
$sapePriFr = $_POST['price_from'];
$sapePriTo = $_POST['price_to'];
$sapeMajC1 = $_POST['mj_cf_1'];
$sapeMajC2 = $_POST['mj_cf_2'];
$sapeMajT1 = $_POST['mj_tf_1'];
$sapeMajT2 = $_POST['mj_tf_2'];
$sapePageN = $_POST['page_number'];
// arrays
$zones = array();
if (isset($_POST['zones'])) {
if (count($_POST['zones']) > 0) {
foreach ($_POST['zones'] as $key => $value) {
$zones[] = $value;
}
}
}
// arrays
$cats = array();
if (isset($_POST['categories'])) {
if (count($_POST['categories']) > 0) {
foreach ($_POST['categories'] as $key => $value) {
$cats[] = $value;
}
}
}
// xml-rpc query
$userSearch = $sape->search($sapeURLID, array("order"=>$sapeOrder,"domain_level"=>$sapeDepth,"domain_zones"=>$zones,"categories"=>$cats,"flag_blocked_in_google"=>$sapeInInG,"level_from"=>$sapePLeve,"days_old_whois"=>$sapeSdays,"words"=>str_replace(" ", "+", $sapeKwdos),"words_type"=>$sapeKwpla,"in_dmoz"=>$sapeSdmoz,"ext_links"=>$sapeExtLi,"pr_from"=>$sapePriFr,"pr_2"=>$sapePriTo,"mj_cf_1"=>$sapeMajC1,"mj_cf_2"=>$sapeMajC2,"mj_tf_1"=>$sapeMajT1,"mj_tf_2"=>$sapeMajT2), $sapePageN);
// is there any results?
if (count($userSearch) == 0) {
stderr("No results with those filters, try again with more options selected.");
}
// loop results
foreach ($userSearch as $val1) {
// ignore blank urls
if (!empty($val1['url'])) {
if ($member == SAPE_USER) {
echo "<pre>";
echo "<br />";
echo "<b>ID:</b> " . $val1['id'];
echo "<br />";
echo "<b>URL:</b> " . $val1['url'];
echo "<br />";
echo "<br />";
}
foreach ($val1['pages'] as $key => $val2) {
$urlCheck = DB::getInstance()->selectOne(
'
SELECT DISTINCT site_sape_url, site_uri
FROM `sites`
WHERE `site_sape_url` = :site_sape_url
AND `site_uri` = :site_uri',
[
'site_sape_url' => $val1['url'],
'site_uri' => $val2['uri']
]
);
// count check
if (!count($urlCheck)) {
// ten op for the site level
$level = ($val2['uri'] == "/") ? '1' : $val2['level'];
// get site ip
$ip = gethostbyname(parse_url($val1['url'], PHP_URL_HOST));
// insertion
DB::getInstance()->insert(
'sites',
[
'site_sape_id' => $val1['id'],
'site_sape_url' => $val1['url'],
'site_uri_id' => $val2['id'],
'site_uri' => $val2['uri'],
'site_uri_price' => $val2['price'],
'site_level' => $level,
'site_pages_in_google' => $val1['nof_pages_in_google'],
'site_ip' => $ip,
'site_added' => date('Y-m-d H:i:s')
]);
}
////////////////////////////////////////////////////////////////////////////////////
// have we already checked the link stats?
/* $already = DB::getInstance()->select("SELECT * FROM `metrics` WHERE `metrics_url`='".trim($val1['url'] . $val2['uri'])."'");
if (!count($already)) {
// vars
$fURL = returnDomDetails(trim($val1['url'] . $val2['uri']));
// domdetailer
$domMajestic = json_decode($fURL);
if ($domMajestic) {
// avoid "PHP Notice: Trying to get property of non-object" warnings
DB::getInstance()->insert(
'metrics',
[
'metrics_user_id' => 1,
'metrics_url' => $metricsURL,
'metrics_moz_links' => $domMajestic->mozLinks,
'metrics_mozPA' => $domMajestic->mozPA,
'metrics_mozDA' => $domMajestic->mozDA,
'metrics_mozRank' => $domMajestic->mozRank,
'metrics_mozTrust' => $domMajestic->mozTrust,
'metrics_FB_comments' => $domMajestic->FB_comments,
'metrics_FB_shares' => $domMajestic->FB_shares,
'metrics_google_plus_one' => $domMajestic->google_plus_one,
'metrics_pinterest_pins' => $domMajestic->pinterest_pins,
'metrics_linkedin' => $domMajestic->linkedin,
'metrics_majesticLinks' => $domMajestic->majesticLinks,
'metrics_majesticRefDomains' => $domMajestic->majesticRefDomains,
'metrics_majesticCF' => $domMajestic->majesticCF,
'metrics_majesticTF' => $domMajestic->majesticTF,
'metrics_date' => date('Y-m-d H:i:s')
]);
}
} */
////////////////////////////////////////////////////////////////////////////////////
if ($member == SAPE_USER) {
echo "<br />";
echo "<b>------------->Page ID:</b> " . $val2['id'];
echo "<br />";
echo "<b>------------->Page:</b> " . $val2['uri'];
echo "<br />";
echo "<br />";
}
}
if ($member == SAPE_USER) {
echo "</pre>";
}
}
}
// show var_dump
if ($member == SAPE_USER) { showPre($userSearch); }
// message
stdmsg('Search complete, view the results here.');
} catch (SapeApiException $e) {
if ($e->getMessage() == "SAPE.RU: Search result is too big :o(") {
stderr('Your search query has too many results, try refining your search options to be more specific.');
} else {
stderr($e->getMessage());
}
}
}
// get the logged in users id
$row = get_logged_in_users_details($member);
// the ID
$hID = $row['member_id'];
?>
<div class="panel panel-primary">
<div class="panel-heading">Search - To get a Link ID you need to create a project.</div>
<div class="panel-body">
<form id="search-form" action="search.php" method="post" class="form-horizontal container-fluid" role="form">
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="txtLinkID" class="control-label">Link ID:</label>
</div>
<div class="col-sm-6">
<select id="txtLinkID" name="url_id" class="form-control" required="required">
<?php
$rows = DB::getInstance()->select('SELECT * FROM `projects` WHERE `project_member_id`='.$hID);
?>
<?php foreach ($rows as $row) { ?>
<option value="<?php echo htmlspecialchars($row['project_sape_link_id']) ?>"><?php echo htmlspecialchars($row['project_sape_link_id']) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="txtLevelDepth" class="control-label">Domain Level:</label>
</div>
<div class="col-sm-6">
<select id="txtLevelDepth" name="domain_level" class="form-control" required="required">
<?php
$level = array(0 => "1",1 => "2",2 => "3");
?>
<?php foreach ($level as $key => $value) { ?>
<option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="txtLevelDepth" class="control-label">Nesting Pages:</label>
</div>
<div class="col-sm-6">
<select id="txtLevelDepth" name="page_level" class="form-control" required="required">
<?php
$nesting = array(0 => "page_level_1",1 => "page_level_2",2 => "page_level_3");
?>
<?php foreach ($nesting as $key => $value) { ?>
<option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="" class="control-label">Categories:</label>
</div>
<div class="col-sm-6">
<?php
$rows = DB::getInstance()->select('SELECT * FROM `categories`');
?>
<?php foreach ($rows as $row) { ?>
<input type="checkbox" name="categories[]" value="<?php echo htmlspecialchars($row['cat_sape_id']) ?>"> - <?php echo htmlspecialchars($row['cat_name']) ?><br>
<?php } ?>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="" class="control-label">Zones:</label>
</div>
<div class="col-sm-6">
<?php
$rows = DB::getInstance()->select('SELECT * FROM `zones`');
?>
<?php foreach ($rows as $row) { ?>
<input type="checkbox" name="zones[]" value="<?php echo htmlspecialchars($row['zone_sape_id']) ?>"> - <?php echo htmlspecialchars($row['zone_name']) ?><br>
<?php } ?>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="" class="control-label">Indexed in Google:</label>
</div>
<div class="col-sm-6">
<select id="" name="indexed_in_google" class="form-control" required="required">
<?php
$depth = array(0 => "Yes",1 => "No",2 => "Does not matter");
?>
<?php foreach ($depth as $key => $value) { ?>
<option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="" class="control-label">Site in DMOZ:</label>
</div>
<div class="col-sm-6">
<select id="" name="site_in_dmoz" class="form-control" required="required">
<?php
$dmoz = array(1 => "No", 0 => "Yes");
?>
<?php foreach ($dmoz as $key => $value) { ?>
<option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="txtCR" class="control-label">Site Must Be older Than (in days):</label>
</div>
<div class="col-sm-6">
<input type="text" id="" name="search_days" value="0" class="form-control" size="40" required="required"/>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="txtCR" class="control-label">Site Must Contain This Keyword:</label>
</div>
<div class="col-sm-6">
<input type="text" id="" name="keyword" value="" class="form-control" size="40" />
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="txtCR" class="control-label">Keyword Should Be:</label>
</div>
<div class="col-sm-6">
<select id="" name="keyword_placement" class="form-control" required="required">
<?php
$depth = array(0 => "On the page somewhere",1 => "In the <title>Keyword(s)</title> tags");
?>
<?php foreach ($depth as $key => $value) { ?>
<option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="txtCR" class="control-label">No More Than This Number of External Links On-Page:</label>
</div>
<div class="col-sm-6">
<input type="text" id="" name="external_links" value="0" class="form-control" size="40" required="required"/>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="txtCR" class="control-label">Price (From):</label>
</div>
<div class="col-sm-6">
<input type="text" id="" name="price_from" value="0" class="form-control" size="40" required="required"/>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="txtCR" class="control-label">Price (To):</label>
</div>
<div class="col-sm-6">
<input type="text" id="" name="price_to" value="500" class="form-control" size="40" required="required"/>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="txtCR" class="control-label">Majestic CF (Min):</label>
</div>
<div class="col-sm-6">
<input type="text" id="" name="mj_cf_1" value="0" class="form-control" size="40" required="required"/>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label">Majestic CF (Max):</label>
</div>
<div class="col-sm-6">
<input type="text" id="" name="mj_cf_2" value="0" class="form-control" size="40" required="required"/>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label">Majestic TF (Min):</label>
</div>
<div class="col-sm-6">
<input type="text" id="" name="mj_tf_1" value="0" class="form-control" size="40" required="required"/>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label">Majestic TF (Max):</label>
</div>
<div class="col-sm-6">
<input type="text" id="" name="mj_tf_2" value="0" class="form-control" size="40" required="required"/>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label for="" class="control-label">Order Results By:</label>
</div>
<div class="col-sm-6">
<select id="" name="order" class="form-control" required="required">
<?php
$depth = array(9 => "Lowest price first",19 => "Highest price first",4 => "Category Descending",14 => "Category Ascending");
?>
<?php foreach ($depth as $key => $value) { ?>
<option value="<?php echo htmlspecialchars($key) ?>"><?php echo htmlspecialchars($value) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label"># Of Pages Of Results:</label>
</div>
<div class="col-sm-6">
<select id="" name="page_number" class="form-control" required="required">
<?php for ($x = 1; $x <= 5; $x++) { ?>
<option value="<?php echo $x ?>"><?php echo $x ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="row form-group">
<div class="col-sm-6 text-right">
<label class="control-label" style="display: inline-block;"> </label>
</div>
<div class="col-sm-6 text-right">
<button type="submit" name="search" class="btn btn-default">Search</button>
<input type="hidden" name="hiddenID" value="<?php echo $hID; ?>" />
</div>
</div>
</form>
</div>
<div class="panel-footer">Search for links using <b>your</b> criteria.</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#search-form').submit(function(){
$('.modal-loading').fadeIn();
var url = $(this).attr('action');
$.post(url, $(this).serialize(), function(html){
$('.modal-loading').fadeOut();
var newDoc = document.open("text/html", "replace");
newDoc.write(html);
newDoc.close();
});
return false;
});
});
</script>
<?php
include('includes/footer.php');
Once the "search" is pressed, i wanted a loading .gif to appear to show the user it's working (this shows fine) the problem is, the form doesn't seem to be submitting, the if (isset($_POST['search'])) { is not being triggered for some reason, can anyone see anything i have missed?
This is the major problem with W3Schools and people following it.
if (isset($_POST['search'])) {
Will never be sent! Or triggered. You need to check the Network Tab for what all is going to the POST request.
You need to check with:
if (count($_POST) > 0) {
Or something that you are sending.
I want to update data with different tables . but it redirect to "The URI you submitted have disallowed characters"I have tables like this. please help me :(((
recipe
category
category_ingredient
ingredient
menu
time
Here's my code:
VIEW:edit_product.php
<?php echo form_open('dashboard/save_edit_recipe/$product_id', 'class="form-horizontal" enctype="multipart/form-data"'); ?>
<?php foreach($recipe_info as $row): ?>
<input type="hidden" id="hide" name="recipe_id" value="<?php echo $row->recipe_id; ?>" class="form-control"><br/>
<div class="form-group">
<div class="col-sm-10">
<input class="form-control" type="text" name="r_name" placeholder="Recipe name" required value="<?php echo $row->r_name; ?>">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<select required class="form-control" name="recipe_category">
<?php $recipe_category = $this->products_model->getRecipeCategory($row->recipe_id); ?>
<option value="" selected disabled>Select Recipe Category</option>
<option value="All">All</option>
<?php foreach($this->products_model->getCategory() as $cat): ?>
<?php if($cat->category_id == $recipe_category): ?>
<option selected value="<?php echo $cat->category_id ?>"><?php echo $cat->name ?></option>
<?php else: ?>
<option value="<?php echo $cat->category_id ?>"><?php echo $cat->name ?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<label>Pick Ingredients:</label>
<div class="row" id="categoryIngredients" >
<?php $ingredients = $this->products_model->getRecipeIngridients($row->recipe_id); ?>
<?php foreach($this->products_model->geIngredientsInCategory($recipe_category) as $ing): ?>
<div class="col-sm-3"><div class="checkbox"><label><input type="checkbox" name="ingredients[]" value="<?php echo $ing->ingredient_id ?>" <?php echo (in_array($ing->ingredient_id, $ingredients) >= -1 ? 'checked' : '') ?>><?php echo $ing->name ?></label></div></div>
<?php endforeach; ?>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<label>Type your Procedure</label><br/>
<textarea id="recipeProcedure" name="recipe_procedure" rows="10" class="form-control" placeholder="Procedure"><?php echo $row->r_procedure ?></textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<select required class="form-control" name="cooking_time">
<option value=""selected disabled>Select Cooking time</option>
<?php foreach($this->products_model->getRecipeCookingTime() as $time): ?>
<?php if($row->time_id == $time->time_id): ?>
<option selected value="<?php echo $time->time_id ?>"><?php echo $time->name ?></option>
<?php else: ?>
<option value="<?php echo $time->time_id ?>"><?php echo $time->name ?></option>
<?php endif; ?>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<textarea class="form-control" rows="5" placeholder="Description" name="r_description" required><?php echo $row->r_description; ?></textarea>
</div>
</div>
<div class="form-group">
<div class='col-sm-10'>
<input class='form-control' type="text" placeholder="Calories" name="calories" required value="<?php echo $row->r_cal ?>">
</div>
</div>
<div class="form-group">
<div class='col-sm-10'>
<input class='form-control' type="text" placeholder="Serving Size" name="serving_size" required value="<?php echo $row->r_serve ?>">
</div>
</div>
<div class="form-group">
<div class="col-sm-10">
<label>Upload Thumbnail</label>
<input type="file" name="r_image" required>
<div>
<img style="width:50%;height:50%;"<?php echo img(base_url().$row->r_image); ?>
</div>
</div>
</div>
<div class='form-group'>
<div class="col-sm-10">
<button class="btn btn-lg btn-positive" type="submit"><i class="glyphicon glyphicon-ok"></i> Save Recipe</button>
</div>
</div>
<?php endforeach; ?>
<?php echo form_close(); ?>
CONTROLLER:
function edit_product($product_id)
{
$data = array('recipe_info' => $this->products_model->getRcipe($this->uri->segment(3)),
'product_id' => $this->uri->segment(3)
);
/*var_dump($data); die();*/
$this->load->view('edit_product', $data);
}
public function save_edit_recipe()
{
$this->load->model('products_model');
$product_id= $this->input->post('recipe_id');
$data = array(
'r_name' => $this->input->post('r_name'),
'r_image' => '',
'r_description' => $this->input->post('r_description'),
'time_id' => $this->input->post('cooking_time'),
'r_cal' => $this->input->post('calories'),
'r_serve' => $this->input->post('serving_size'),
);
$this->products_model->update_product($product_id,$data);
$this->getRcipe();
}
MODEL:products_model.php
function getRcipe($recipe_id)
{
$this->db->where('recipe_id', $recipe_id);
$query = $this->db->get('recipe');
return $query->result();
}
Find what your disallowed characters are which will be in your url it could be ?&=
Then go to your config.php and you can add them here.
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
Restart or Refresh Server afterwords.
Also in your form_open
<?php echo form_open('dashboard/save_edit_recipe/$product_id', 'class="form-horizontal" enctype="multipart/form-data"'); ?>
To $product_id product id was not correct
<?php echo form_open('dashboard/save_edit_recipe/' . $product_id, 'class="form-horizontal" enctype="multipart/form-data"'); ?>
If you need to use mulitpart / form helper codeigniter one
<?php echo form_open_multipart('dashboard/save_edit_recipe' .'/'. $product_id, array('class' => 'form-horizontal'));?>
Update:
$this->products_model->update_product($this->uri->segment(3), $data);
I want to set the value to selected that has been selected in dropdown list and also want to print that value that has been submitted in that form.
When i print print_r[$value];
i just get some values.
Below is my code:
<form method="post" action="" id="date_date" name="date_data">
<div class="col-sm-4">
<h3><label for="sel1">Select From Date:</label></h3>
<h3><?php echo $this->input->post('date_data');?></h3>
<input type="text" id="datepicker" name="date_data">
</div>
<div class="col-sm-4">
<h3><label for="sel1">Select To Date:</label></h3>
<h3><?php echo $this->input->post('to_data');?></h3>
<input type="text" id="datepicker_to" name="to_data">
</div>
<div class="col-sm-4">
<?php
$user_type = $this->session->userdata('user_type');
if($user_type =="admin")
{
?>
<div class="form-group">
<h3><label for="sel1">Select Employoee Name:</label></h3>
<select name="attendance-list" id="attendance-list" class="form-control" >
<?php foreach($attendance_dropdown as $value)
{
?>
<option id="emp" value="<?php echo $value['emp_id'];?>"><?php echo $value['emp_name'];?></option>
$dropdown = str_replace("value='".$rid."'","value='".$rid."' selected=\"selected\"",$dropdown);
<?php
}
?>
</select>
<?php echo "<br>"; ?>
</div>
<?php
}
else
{
?>
<div class="form-group">
<input type="hidden" name="attendance-list" value="<?php echo $this->session->userdata('emp_id'); ?>">
</div>
<?php
}
?>
</div> <!--Col-sm-8-->
<div class="col-sm-4">
<h3><label for="sel1"></label></h3>
<input type="submit" value="submit" class="btn btn-primary">
</div>
</form>
Here is your answer, it will select your last select dropdown state...
Remove id from option <option id="emp" use class if you want, or use unique id.
<select name="attendance-list" id="attendance-list" class="form-control" >
<?php
$save_drop_down_value = $this->input->post('attendance-list"');
//change this line according to your project..
foreach($attendance_dropdown as $value) {
$select = "";
if( $save_drop_down_value == $value['emp_id']){
$select = "selected";
}
?>
<option <?php echo $select; ?> value="<?php echo $value['emp_id'];?>">
<?php echo $value['emp_name'];?>
</option>
<?php } ?>