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.
Related
<?php
if(isset($_POST['updatecustomer'])){
$customerID=trim($_POST['customerID']);
$customername=trim($_POST['customername']);
$mobilenumber=trim($_POST['mobilenumber']);
$Description=trim($_POST['description']);
$area=trim($_POST['area']);
if(empty($customername)){
$errorcustomername="Please Enter Customer Name";
}
elseif (empty($mobilenumber)) {
$Errormobilenumber="Please Enter Mobile Number";
}
elseif (empty($Description)) {
$Errordescription="Please Enter Description";
}
elseif (empty($area)) {
$Errorarea="Please Enter Address";
}
else
{
try {
if (trim($_FILES["image"]["name"])!=""){
$base=explode(".", strtolower(basename($_FILES["image"]["name"])));
$ext=end($base);
if($ext=="png" or $ext=="jpg" or $ext=="jpeg"){
$image1 = getimagesize($_FILES["image"]["tmp_name"]);
$width = $image1[0];
$height = $image1[1];
if($width<256 || $height<256){
$error = true;
$ErrorImage = "Please select an image with minimum resolution of 256x256 !";
}else{
$image1=uniqid().".".$ext;
move_uploaded_file($_FILES["image"]["tmp_name"], "picture/" . $image1);
$image1="picture/".$image1;
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/update Query/
$sql="UPDATE customer SET shopID='$shopID',name='$customername',
mobile='$mobilenumber',area='$area',description='$Description',picture='$image1' WHERE customerID='$customerID'";
$con->exec($sql);
$sql1="UPDATE customerdetails SET area='$area' WHERE customerID='$customerID' ";
if (mysqli_query($conn,$sql1)) {
$success="Customer Updated Successfully";
}
else
{
$errorSubmit="Customer not Updated";
}
}
}
else {
}
$error = true;
$ErrorImage="invalid image extension !";
}
else {
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql="UPDATE customer SET shopID='$shopID',name='$customername',mobile='$mobilenumber,area='$area',description='$Description' WHERE customerID='$customerID'";
$con->exec($sql);
$sql1="UPDATE customerdetails SET area='$area' WHERE customerID='$customerID' ";
if (mysqli_query($conn,$sql1)) {
$success="Customer Updated Successfully";
}
else
{
$errorSubmit="Customer not Updated";
}
}
}
catch(PDOException $e)
{
$errorSubmit= $e->getMessage();
}
}
}
?>
<div class="boxed">
<div id="content-container">
<div id="page-title">
<h1 class="page-header text-overflow">Update Customer</h1>
</div>
<ol class="breadcrumb">
<li>Dashboard</li>
<li>Customer</li>
<li class="active">Update Customer</li>
</ol>
<div id="page-content">
<div class="col-sm-12" style="padding-bottom: 5%">
<div class="panel">
<div class="panel-heading">
<h3 class="panel-title">Update Customer Details</h3>
</div>
<form class="form-horizontal" method="POST" enctype="multipart/form-data">
<div class="panel-body">
<?php
/join Query/
$id=mysqli_real_escape_string($conn,$_GET['id']);
$sql="SELECT customer.*,customerdetails.* FROM customer JOIN customerdetails ON customer.customerID=customerdetails.customerID WHERE customer.customerID='$id'";
$read=mysqli_query($conn,$sql);
while ($row1=mysqli_fetch_assoc($read)) {
# code...
?>
<input type="hidden" name="customerID" value="<?php echo $row1['customerID']; ?>">
<div class="form-group">
<label class="col-sm-3 control-label" for="demo-hor-inputemail">Customer Name</label>
<div class="col-sm-9">
<input type="text" name="customername" class="form-control" placeholder="Customer Name" value="<?php echo $row1['name']; ?>"
oninput="this.value = this.value.replace(/[^A-Za-z ]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" maxlength="60" required="">
<?php if (!empty($errorcustomername)) { ?> <p class="label label-danger"><?php echo $errorcustomernamee; ?></p> <?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="demo-hor-inputemail">Mobile Number</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="mobilenumber" placeholder="Mobile Number" value="<?php echo
$row1['mobile'];?>" oninput="this.value = this.value.replace(/[^0-9- ]/g, ''); this.value = this.value.replace(/(\..*)\./g, '$1');" maxlength="10"/>
<?php if (!empty($Errormobilenumber)) { ?> <p class="label label-danger"><?php echo $Errormobilenumber; ?></p> <?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="demo-hor-inputemail">Address</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="area" placeholder="Address" value="<?php echo $row1['area'];?>" />
<?php if (!empty( $Errorarea)) { ?> <p class="label label-danger"><?php echo $Errorarea; ?></p> <?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="demo-hor-inputemail">Description</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="description" placeholder="Description" value="<?php echo $row1['description'];?>" />
<?php if (!empty($Errordescription)) { ?> <p class="label label-danger"><?php echo $Errordescription; ?></p> <?php } ?>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="demo-hor-inputemail">Picture</label>
<div class="col-sm-9">
<input type="file" class="form-control" name="image" placeholder="Password" value="<?php echo $row1['image'];?>"
/>
<?php if (!empty($Errorimage)) { ?> <p class="text text-danger"><?php echo $Errorimage; ?></p> <?php } ?>
</div>
</div>
<?php
}
?>
</div>
<div align="center">
<?php if (!empty($success)) { ?> <span class="label label-success"><?php echo $success; ?></span> <?php } ?>
<?php if (!empty($errorSubmit)) { ?> <span class="label label-danger"><?php echo $errorSubmit; ?></span> <?php } ?>
</div>
<div class="panel-footer text-right">
<button class="btn btn-success" type="submit" name="updatecustomer">Update Customer</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
include 'include/sidebar.php';
include 'include/footer.php';
?>
<?php
}
else
{
header('location:login.php');
}
?>
please check first area is inserting to DB or not?
i have form in which there are 2 dropdowns which are select batch from first dropdown and according to that batch, students will appear in second dropdown , Right now i am getting dropdown of batch but, not getting dropdown of students using batch
This is my view
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use common\models\TblBetch;
use common\models\TblCompany;
use common\models\TblCourse;
use common\models\TblStudent;
use common\models\TblStudentExpence;
use kartik\widgets\DepDrop;
use yii\db\Query;?><link rel="shortcut icon" href="<?php echo Yii::$app->params['global_theme_path'];?>images/logo1.png" type="image/png"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><script src="http://iamrohit.in/lab/js/location.js"></script><div class="pageheader"><h2><i class="fa fa-money"></i>Expense</h2>
<div class="breadcrumb-wrapper">
<span class="label">You are here:</span>
<ol class="breadcrumb">
<li>Westline Shipping</li>
<li class="active">Add Expense</li>
</ol></div></div><div class="contentpanel">
<?php
$session = Yii::$app->session;
if($session->hasFlash('success'))
{
echo $session->getFlash('success');
}
if($session->hasFlash('error'))
{
echo $session->getFlash('error');
}
$site = '';
?>
<div class="row">
<div class="col-md-12">
<div class="container-fluid-50">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-btns">
−
</div>
<h4 class="panel-title">Add Expense</h4>
</div>
<form class="panel-body" action="dashboard" method="post">
<div class="row">
<?php $form = ActiveForm::begin(); ?>
<div class="col-sm-9">
<div class="form-group">
<label class="control-label"></label>
<?php
//$batch = new TblBetch();
//$quer = new Query();
//$getid = [''];
//$getid = $quer->select('b_sn')->from($batch->tableName())->all();
//echo $form->field($model,'se_b_id')->dropDownList($getid,['id'=>'se_b_id']);
?>
<?=
$form->field($model,'se_s_id')->dropDownList(
ArrayHelper::map(TblBetch::find()->all(),'b_id','b_sn'),
[
'prompt'=>'Select Batch',
'name'=>'s_b_id',
'id'=>'s_b_id',
'onchange'=>'$.post("student?id="+$(this).val(),function(data){$("select#tblstudentexpence-se_s_id").html(data);});'
]);
?>
</div>
</div><!-- col-sm-6 -->
<div class="col-sm-9">
<div class="form-group">
<label class="control-label"></label>
<?=
$form->field($model,'se_s_id')->dropDownList(
ArrayHelper::map(TblStudent::find()->all(),'s_id','s_fname'),
[
'prompt'=>'Select Student',
'name'=>'se_s_id',
'id'=>'se_s_id'
]);
?>
</div>
</div><!-- col-sm-6 -->
<div class="col-sm-9">
<div class="form-group">
<label class="control-label">Payment Mode</label>
<div class="radio"><label><input type="radio" name="num" value="cash" required> Cash </label></div>
<div class="radio"><label><input type="radio" name="num" value="check" required> Check </label></div>
<div class="radio"><label><input type="radio" name="num" value="dd" required> DD </label></div>
</div>
</div><!-- col-sm-6 -->
<div class="col-sm-9">
<div class="form-group">
<label class="control-label">Check / DD No</label>
<input type="text" name="num" id="num" class="form-control" placeholder="Enter your check or DD number" required/>
</div>
</div><!-- col-sm-6 -->
<div class="col-sm-9">
<div class="form-group">
<label class="control-label">Amount</label>
<input type="text" name="lastname" class="form-control" placeholder="Enter your Amount" required/>
</div>
</div><!-- col-sm-6 -->
<div class="col-sm-9">
<div class="form-group"> <br><br>
<input type="submit" value="Submit" class="btn btn-primary">
<input type="reset" value="Cancel" class="btn btn-primary">
</div></div>
</div><!-- row -->
</form>
</div><!-- panel-body -->
</div>
</div>
</div> <div class="col-md-12">
</div>
</div></div></div> <script>
$(function() {
window.invalidate_input = function() {
if ($('input[name=num]:checked').val() == "check" || $('input[name=num]:checked').val() == "dd")
$('#num').removeAttr('disabled');
else
$('#num').attr('disabled', 'disabled');
};
$("input[name=num]").change(invalidate_input);
invalidate_input();
});
This is my controller (sitecontroller.php)
public function actionStudent($id)
{
//p($id);
$student = new TblStudent();
$queryobj = new Query();
$data = [];
$data = $queryobj->select('*')->from($student->tableName())->where(['s_betch'=>$id])->count();
//p($data);
$queryobj1 = new Query();
$getid = [];
$getid = $queryobj->select('*')->from($student->tableName())->where(['s_betch'=>$id])->all();
//p($getid);
if($data > 0)
{
foreach($getid as $gid)
{
echo "<option value='".$gid->s_id."'>".$gid->s_fname."</option>";
}
}
else
{
echo "<option> - </option>";
}
}
I am getting this response in firebug after ajax call
You can implement dependent drop-down much simpler in yii 2 because there is a widget available which you can use.
use kartik widget here -> kartik dependent drop down
I have simple code thats not working. I made validation for checkbox and I get error:
Unable to access an error message corresponding to your field name accept_terms_checkbox.(accept_terms)
This is my code:
Controller:
public function formularz2()
{
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$data['szkolenia'] = $this->Szkolenie_m->pobierz();
//VALIDATION!!
$this->form_validation->set_rules('imie', 'Imię', 'required');
$this->form_validation->set_message('required', 'Błąd: wypełnij powyższe pole');
$this->form_validation->set_rules('accept_terms_checkbox', 'checkbox', 'callback_accept_terms');
//CALLBACK FUNCTION!!
function accept_terms()
{
if ($this->input->post('accept_terms_checkbox'))
{
return TRUE;
}
else
{
$error = 'Please read and accept our terms and conditions.';
$this->form_validation->set_message('accept_terms', $error);
return FALSE;
}
}
//Po przesłaniu danych
if (!empty($_POST))
{
$konsultant = $this->uri->segment(3);
$dane = array(
'email1' => $this->input->post('email'),
'imie' => $this->input->post('imie'),
'nazwisko' => $this->input->post('nazwisko'),
'nazwa_firmy' => $this->input->post('firma'),
'konsultant_id' => $konsultant,
);
//Trzeba jeszcze tutaj ogarnąć wrzucanie pivotów zaznaczonych checkboxów
$boxes = $_POST['formChecks'];
$N = count($boxes);
$ostatni_id = $this->Osoby_m->ostatni_id();
for($i=0; $i < $N; $i++)
{
$this->Osoby_m->nowy_wpis_formularz($boxes[$i]);
}
//Pobrać id dodanej osoby = policzyć ile osób w bazie +1
$this->Osoby_m->nowa_osoba($dane);
}
if ($this->form_validation->run() == FALSE)
{
$this->load->view('formularz', $data);
}
else
{
$this->load->view('wyslano_formularz');
}
}
My View:
<?php echo form_open(); ?>
<div class="form-group">
<label for="email" class="col-sm-2 control-label">Email:</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" placeholder="Email" value="<?php echo set_value('email'); ?>">
<p class="help-block"><?php echo form_error('email'); ?></p>
</div>
</div>
<div class="form-group">
<label for="imie" class="col-sm-2 control-label">Imię:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="imie" name="imie" placeholder="Imię" value="<?php echo set_value('imie'); ?>">
<p class="help-block"><?php echo form_error('imie'); ?></p>
</div>
</div>
<div class="form-group">
<label for="nazwisko" class="col-sm-2 control-label">Nazwisko: </label>
<div class="col-sm-10">
<input type="text" class="form-control" id="nazwisko" name="nazwisko" placeholder="Nazwisko" value="<?php echo set_value('nazwisko'); ?>">
<p class="help-block"><?php echo form_error('nazwisko'); ?></p>
</div>
</div>
<div class="form-group">
<label for="firma" class="col-sm-2 control-label">Firma:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="firma" name="firma" placeholder="Firma" value="<?php echo set_value('firma'); ?>">
<p class="help-block"><?php echo form_error('firma'); ?></p>
</div>
</div>
<div class="col-sm-12" style="margin-bottom: 30px; margin-top: 30px;"> <h3>Wybierz interesujące Cię szkolenia</h3></div>
<div class="form-group">
<label class="col-sm-2 control-label">Szkolenia:</label>
<div class="col-sm-10">
<?php foreach ($szkolenia as $szkolenie): ?>
<div class="checkbox">
<label><input id="szkolenie<?php echo $szkolenie->id; ?>" type="checkbox" name="formChecks[]" value="<?php echo $szkolenie->id; ?>"> <?php echo $szkolenie->nazwa_szkolenia; ?></label>
<br>
</div>
<?php endforeach; ?>
</div>
</div>
//CALLBACK CHECKBOX
<div class="form-group">
<div class="col-sm-12" style="margin-top: 50px;">
<input type="checkbox" name="accept_terms_checkbox" value="1"/> Zgadzam się na otrzymywanie maili od firmy Gamma<br>
<p><?php echo form_error('accept_terms_checkbox') ?></p>
</div>
</div>
<button type="submit" class="btn btn-lg btn-success" style="margin-top: 50px;">Odbierz Voucher</button>
<?php echo form_close(); ?>
In order to use your own callback method with codeigniter's validation class, you must declare the method. IN your case ( add this to your controller or a helper etc...):
public function accept_terms($user_input){
if($user_input != ""){
return True;
}else{
$this->form_validation->set_message('accept_terms_checkbo', 'The %s field can not be empty"');
return False;
}
I fixed this error by simple validation without callback function. I figure out that I don't need callback function for Terms of Services checkbox.
$this->form_validation->set_rules('accept_terms_checkbox', 'Checkbox', 'required');
$this->form_validation->set_message('required', 'You need to accept Terms of Services');
I want to make subsector dependent on sector, i am not using jquery nor ajax
This is my Controller
<?php
/*
*/
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Salesforce extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->helper('form');
$this->load->helper('url');
$this->load->database();
$this->load->library('form_validation');
//load the employee model
$this->load->model('sf_model');
}
//index function
function index()
{
//...
$data['sector'] = $this->sf_model->get_sector();
$data['subsector'] = $this->sf_model->get_subsector();
$data['type'] = $this->sf_model->get_type();
//set validation rules
$this->form_validation->set_rules('a_name', 'Account Name', 'trim|required|xss_clean|callback_alpha_only_space');
$this->form_validation->set_rules('a_web', 'Website', 'trim|required|xss_clean');
$this->form_validation->set_rules('a_type', 'Type', 'callback_combo_check');
$this->form_validation->set_rules('a_sector', 'Sector', 'callback_combo_check');
$this->form_validation->set_rules('a_subsector', 'Sub Sector', 'callback_combo_check');
if ($this->form_validation->run() == FALSE)
{
//fail validation
//echo 'Validation failed';
//print_r($_REQUEST);
$this->load->view('sf_view', $data);
//
}
else
{
//pass validation
$data = array(
'a_name' => $this->input->post('a_name'),
'a_website' => $this->input->post('a_web'),
't_id' => $this->input->post('a_type'),
's_id' => $this->input->post('a_sector'),
'ss_id' => $this->input->post('a_subsector'),
'a_billingStreet' => $this->input->post('a_billingStreet'),
'a_billingState' => $this->input->post('a_billingState'),
'a_billingZip' => $this->input->post('a_billingZip'),
'a_billingCountry' => $this->input->post('a_billingCountry'),
'a_billingCity' => $this->input->post('a_billingCity'),
'a_phone' => $this->input->post('a_phone'),
'a_mobile' => $this->input->post('a_mobile'),
'a_fax' => $this->input->post('a_fax'),
);
//print_r($data);
//exit;
//insert the form data into database
$this->db->insert('account_info', $data);
//display success message
$this->session->set_flashdata('msg', '<div class="alert alert-success text-center">New Account Created</div>');
redirect('salesforce/index');
}
}
//custom validation function for dropdown input
function combo_check($str)
{
if ($str == '-SELECT-')
{
$this->form_validation->set_message('combo_check', 'Valid %s Name is required');
return FALSE;
}
else
{
return TRUE;
}
}
//custom validation function to accept only alpha and space input
function alpha_only_space($str)
{
if (!preg_match("/^([-a-z ])+$/i", $str))
{
$this->form_validation->set_message('alpha_only_space', 'The %s field must contain only alphabets or spaces');
return FALSE;
}
else
{
return TRUE;
}
}
}
This is my Model
<?php
class Sf_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
function get_sector()
{
$results = $this->db->select('s_id, s_name')->from('account_sector')->get()->result();
$s_id = array('-SELECT-');
$s_name = array('-SELECT-');
for ($i = 0; $i < count($results); $i++)
{
array_push($s_id, $results[$i]->s_id);
array_push($s_name, $results[$i]->s_name);
}
return $sector_result = array_combine($s_id, $s_name);
}
function get_subsector()
{
$results = $this->db->select('ss_id, ss_name')->from('account_subsector')->get()->result();
$ss_id = array('-SELECT-');
$ss_name = array('-SELECT-');
for ($i = 0; $i < count($results); $i++)
{
array_push($ss_id, $results[$i]->ss_id);
array_push($ss_name, $results[$i]->ss_name);
}
return $subsector_result = array_combine($ss_id, $ss_name);
}
function get_type()
{
$results = $this->db->select('t_id, t_name')->from('account_type')->get()->result();
$t_id = array('-SELECT-');
$t_name = array('-SELECT-');
for ($i = 0; $i < count($results); $i++)
{
array_push($t_id, $results[$i]->t_id);
array_push($t_name, $results[$i]->t_name);
}
return $type_result = array_combine($t_id, $t_name);
}
}
>
This is my View
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SalesForce | Edit / New Account Details</title>
<!--link the bootstrap css file-->
<link href="<?php echo base_url("bt/css/bootstrap.css"); ?>" rel="stylesheet" type="text/css" />
<!-- link jquery ui css-->
<link href="<?php echo base_url('bt/css/jquery-ui.min.css'); ?>" rel="stylesheet" type="text/css" />
<!--include jquery library-->
<script src="<?php echo base_url('bt/js/jquery-1.11.3.js'); ?>"></script>
<!--load jquery ui js file-->
<script src="<?php echo base_url('bt/js/jquery-ui.min.js'); ?>"></script>
<style type="text/css">
.colbox {
margin-left: 0px;
margin-right: 0px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-offset-3 col-lg-6 col-sm-6 well">
<legend>Account Information</legend>
<?php
$attributes = array("class" => "form-horizontal", "id" => "accounts", "name" => "accounts");
echo form_open("salesforce", $attributes);?>
<fieldset>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_name" class="control-label">Account Name</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="a_name" name="a_name" placeholder="Enter Account Name" type="text" class="form-control" value="<?php echo set_value('a_name'); ?>" />
<span class="text-danger"><?php echo form_error('a_name'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_web" class="control-label">Website</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="a_web" name="a_web" placeholder="Enter Website" type="text" class="form-control" value="<?php echo set_value('a_web'); ?>" />
<span class="text-danger"><?php echo form_error('a_web'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_type" class="control-label">Type</label>
</div>
<div class="col-lg-8 col-sm-8">
<?php
$attributes = 'class = "form-control" id = "a_type"';
echo form_dropdown('a_type',$type,set_value('a_type'),$attributes);?>
<span class="text-danger"><?php echo form_error('a_type'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_sector" class="control-label">Sector</label>
</div>
<div class="col-lg-8 col-sm-8">
<?php
$attributes = 'class = "form-control" id = "a_sector"';
echo form_dropdown('a_sector',$sector,set_value('a_sector'),$attributes);?>
<span class="text-danger"><?php echo form_error('a_sector'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_subsector" class="control-label">Sub Sector</label>
</div>
<div class="col-lg-8 col-sm-8">
<?php
$attributes = 'class = "form-control" id = "a_subsector"';
echo form_dropdown('a_subsector',$subsector, set_value('a_subsector'), $attributes);?>
<span class="text-danger"><?php echo form_error('a_subsector'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_billingStreet" class="control-label">Billing Street</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="a_billingStreet" name="a_billingStreet" placeholder="Enter Billing Street" type="text" class="form-control" value="<?php echo set_value('a_billingStreet'); ?>" />
<span class="text-danger"><?php echo form_error('a_billingStreet'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_billingState" class="control-label">B-State/Province</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="a_billingState" name="a_billingState" placeholder="Enter State/Province" type="text" class="form-control" value="<?php echo set_value('a_billingState'); ?>" />
<span class="text-danger"><?php echo form_error('a_billingState'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_billingZip" class="control-label">B-Zip/Postal</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="a_billingZip" name="a_billingZip" placeholder="Enter Zip/Postal" type="text" class="form-control" value="<?php echo set_value('a_billingZip'); ?>" />
<span class="text-danger"><?php echo form_error('a_billingZip'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_billingCountry" class="control-label">Billing Country</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="a_billingCountry" name="a_billingCountry" placeholder="Enter Billing Country" type="text" class="form-control" value="<?php echo set_value('a_billingCountry'); ?>" />
<span class="text-danger"><?php echo form_error('a_billingCountry'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_billingCity" class="control-label">Billing City</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="a_billingCity" name="a_billingCity" placeholder="Enter Billing City" type="text" class="form-control" value="<?php echo set_value('a_billingCity'); ?>" />
<span class="text-danger"><?php echo form_error('a_billingCity'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_phone" class="control-label">Phone</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="a_phone" name="a_phone" placeholder="Enter Phone Number" type="text" class="form-control" value="<?php echo set_value('a_phone'); ?>" />
<span class="text-danger"><?php echo form_error('a_phone'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_mobile" class="control-label">Mobile Number</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="a_mobile" name="a_mobile" placeholder="Enter Mobile Number" type="text" class="form-control" value="<?php echo set_value('a_mobile'); ?>" />
<span class="text-danger"><?php echo form_error('a_mobile'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="row colbox">
<div class="col-lg-4 col-sm-4">
<label for="a_fax" class="control-label">Fax Number</label>
</div>
<div class="col-lg-8 col-sm-8">
<input id="a_fax" name="a_fax" placeholder="Enter Fax Number" type="text" class="form-control" value="<?php echo set_value('a_fax'); ?>" />
<span class="text-danger"><?php echo form_error('a_fax'); ?></span>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-lg-8 col-sm-8 text-left">
<input id="btn_add" name="btn_add" type="submit" class="btn btn-primary" value="Insert" />
<input id="btn_cancel" name="btn_cancel" type="reset" class="btn btn-danger" value="Cancel" />
</div>
</div>
</fieldset>
<?php echo form_close(); ?>
<?php echo $this->session->flashdata('msg'); ?>
</div>
</div>
</div>
</body>
</html>
Controller
$data['sector'] = $this->sf_model->get_sector();
if(isset($data['sector'])&&$data['sector']!="")
$data['subsector'] = $this->sf_model->get_subsector($data['sector']);
Model, In model pass sector as parameter to get_subsector function and then during database select please pass it to where or as per your requirement you may procced.
Also Please avoid array_push() function in loops, use $ss_id[] = $results[$i]->ss_id; because it is much faster.
function get_subsector($sector)
{
$results = $this->db->select('ss_id, ss_name')->from('account_subsector')->get()->where($sector)->result();
$ss_id = array('-SELECT-');
$ss_name = array('-SELECT-');
for ($i = 0; $i < count($results); $i++)
{
array_push($ss_id, $results[$i]->ss_id);
array_push($ss_name, $results[$i]->ss_name);
}
return $subsector_result = array_combine($ss_id, $ss_name);
}
using some js and ajax
<script>
$(document).ready(function(){
$('#a_subsector').attr('disabled','disabled');
$('#a_sector').change(function(){
$.ajax({
url:'/salesforce/fill_ss',
type:'post',
data: {sector:$('#a_sector').val()},
success:function(result){
$('#a_subsector').removeAttr('disabled');
//$('#a_subsector').(result);
document.getElementById('a_subsector').innerHTML=result;
}
});
});
});
</script>
Adding a Function to controller
function fill_ss()
{
$this->sf_model->get_subsector();
$sector = $_POST['sector'];
$data = $this->sf_model->matching($sector);
//print_r($data);
for ($i = 0; $i < count($data); $i++)
{
echo '<option value="'.$data[$i]->ss_id.'">'.$data[$i]->ss_name.'</option>';
//echo '<option value="'.$data[$i]->ss_id.'"></option>';
//array_push($t_id, $data[$i]->t_id);
//array_push($t_name, $data[$i]->t_name);
}
}
Model
function view_accounts()
{
$results = $this->db->select('a_name,t_id,a_website,a_billingStreet,a_billingZip,a_billingCountry,a_billingCity,a_phone,a_mobile')->from('account_info')->get()->result();
return $results;
}
function matching($match)
{
$results =$this->db->select('ss_id,ss_name')->from('account_subsector')->where('s_id',$match)->get()->result();
return $results;
}
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.