I included an autocomplete widget inside my view which initially(first page load) works fine and i make an ajax call to update the CListView inside my main page and thats where my autocomplete doesnt show completions(the input box is there but when the user type no suggestion is loaded)..i have seen a lot of issue about using renderPartial and ajax calls not working...anyone with a good solution or please suggest me..
here is my main view that is being refreshed by ajaxcall on the same page..
<div id="top" class="row-fluid" style="margin:0 30 auto 30; ;width:100%;">
<?php
?>
<div id="messages" style="width:35%!important;float:left;margin-left:100px;margin- right:20px!important;position:relative; overflow: hidden;">
<?php
$this->renderPartial('ajaxindex',array('dataProvider'=>$dataProvider),false,true);
?>
<!--end of portlet"-->
</div>
<!--end of messages-->
<div id="nav-panel" class="portlet" style="float:left!important;
width:40%!important;border:1px;box-shadow: 10px 10px 5px #888888;" >
<div class="panel panel-success portlet-decoration">
<!-- Default panel contents -->
<div class="panel-heading">
Filtering Panel >> Rwanda
</div>
</div>
<table class="table table-condensed">
<tr>
<th>Province</th>
<th>Critical</th>
<th>Attention</th>
<th>Normal</th>
<th>Nothing</th>
<th>error</th>
<th>count</th>
</tr>
<?php
$i=1;
$countNothing=0;
$countNormal=0;
$countAttention=0;
$countCritical=0;
$countError=0;
$countAll=0;
foreach($messagesByProvinces as $messagesByProvince){
$province=Province::Model()->findByPk($i);
$provinceParams=null;
$messageParams=null;
$critical=0;
$attention=0;
$normal=0;
$nothing=0;
$error=0;
$count=count($messagesByProvince);
foreach($messagesByProvince as $message){
$countAll++;
if($message->indice==0){
$nothing++;
$countNothing++;
}
elseif($message->indice==1){
$normal++;
$countNormal++;
}
elseif($message->indice==2){
$attention++;
$countAttention++;
}
elseif($message->indice==3){
$critical++;
$countCritical++;
}
else {
$error++;
$countError++;
}
}
if($filter!==null){
$provinceParams=array('message/getProvincereport','id'=>$province->id,'start_date'=>$filter['start_date'],'end_date'=>$filter['end_date']);
$messageParams=array('message/LoadMessages','province_id'=>$province->id,'start_date'=>$filter['start_date'],'end_date'=>$filter['end_date']);
}
else {
$provinceParams=array('message/getProvincereport','id'=>$province->id);
$messageParams=array('message/LoadMessages','province_id'=>$province->id);
}
echo "<tr><td>".CHtml::link($province->name,$provinceParams)."</td>
<td><span class='badge badge-important'>".CHtml::ajaxLink($critical,$this->associate('indice',3,$messageParams),array('update'=>'#messages','success'=>'js:function(data){
var $response=$(data);
var newData=$response.find(".container-fluid").html();
$("#messages").html(newData);
} '))."</span></td>";
Here is the view that is rendered in renderPartial
<script>
function showInput(id){
if(document.getElementById('message-body-'+id).style.display=='block')
document.getElementById('message-body-'+id).style.display='none';
else
document.getElementById('message-body-'+id).style.display='block';
;
}
</script>
<?php
/* #var $this MessageController */
/* #var $dataProvider CActiveDataProvider */
?>
<div id="portlet-messages" class="portlet" style="float:left!important;
width:100% !important;max-height:450px;overflow:auto;
overflow-x:hidden;" >
<div class="panel panel-primary portlet-decoration">
<!-- Default panel contents -->
<div class="panel-heading">
<i class="icon-envelope"></i> Messages
</div>
</div>
<table class="table table-striped">
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'summaryText'=>'',
'enablePagination'=>false,
'itemView'=>'_ajaxview',
)); ?>
</table>
</div>
and the the embed view that contains the bogus code of from CAutoComplete Widget..
<?php
$indiceDisplay='Error';
$label="label-default";
if($data->indice==0){
$indiceDisplay="Nothing";
$label="label-info";
}
elseif($data->indice==1){
$indiceDisplay="Normal";
$label="label-success";
}
elseif($data->indice==2){
$indiceDisplay="Attention";
$label="label-warning";
}
elseif($data->indice==3){
$indiceDisplay="Critical";
$label="label-important";
}
else{
$indiceDisplay="Error";
$label="label-default";
}
echo "<tr class='view' >";
?>
<td>
<?php
echo CHtml::encode(User::Model()->findByPK($data->user_id)->names);echo "<br/></br>";
?>
</td>
<td>
<?php
echo "<b>";
echo CHtml::encode( date_format(new DateTime($data->date), 'g:ia \o\n l jS F Y'));?>
<?php
echo " ";
echo " ";
$linkText="<span class='label ".$label." '> ".$indiceDisplay." </span>";
echo CHtml::link($linkText,array('message/index','indice'=>$data->indice));
echo"</br>";
?>
</b>
</br>
<?php echo CHtml::encode($data->content); ?>
<br />
<?php
echo " <b>Location :</b> ".CHtml::link(Province::Model()->findByPk($data- >province_id)->name,array('message/index','province_id'=>$data->province_id))." ".Chtml::link(District::Model()->findByPk($data->district_id)- >name,array('message/index','district_id'=>$data->district_id))." ".CHtml::link(Sector::Model()->findByPk($data->sector_id)- >name,array('message/index','sector_id'=>$data->sector_id))." ".CHtml::link(Cell::Model()- >findByPk($data->cell_id)->name,array('message/index','cell_id'=>$data->cell_id))." ";
?>
<div id="results-<?echo $data->id;?>">
</div>
<?php echo "<div id='message-body-".$data->id."' style='font-size:12px;display:none;'>";?>
<div class="input-append">
<span>Add Category</span>
<?php $this->widget('CAutoComplete', array(
'model'=>$data,
'attribute'=>'category',
'url'=>array('message/suggestCategory'),
'multiple'=>true,
'htmlOptions'=>array('style'=>'height:11px;font-weight: bold;','maxlength'=>255,'value'=>$data->category,'id'=>'category-'.$data->id,))); ?>
<?php echo CHtml::ajaxSubmitButton('Save',$this- >createUrl('message/categorize',array('id'=>$data->id,'category'=>'js:function(){return $("#category-'.$data->id.'").val();}')),
array(
'type'=>'post',
'data'=>array('category'=>'js:function(){return $("#category-'.$data->id.'").val();}'),
'success'=>'function(data) {
if(data.status=="success"){
$("#results-'.$data->id.'").html(data);
$("#message-body-'.$data->id.'").style.display="none";
}
else{
$("#results-'.$data->id.'").html(data);
document.getElementById("message-body-'.$data->id.'").style.display="none";
}
}',
),array('id'=>'mybtn-'.$data->id,'class'=>'btn btn-small btn- primary','style'=>'height:21px'));
?>
</div>
</div>
</td>
<td>
<a class="btn btn-small" onclick="showInput(<?php echo $data->id;?>);"><i class="icon icon- edit"></i>
</a>
</td>
</tr>
here is the method that is called through the ajax call to update the message div in the main page posted at the begining of the code..
public function actionLoadmessages()
{ $criteria=$this->getCriteria();
if(isset($_REQUEST['indice'])){
$criteria->addCondition('indice=:ind');
$criteria->params['ind']=$_REQUEST['indice'];
}
$dataProvider=new CActiveDataProvider('Message',array('criteria'=>$criteria));
$this->layout=null;
$this->render('ajaxindex',array('dataProvider'=>$dataProvider));
}
You should apply post processing of javascript after the ajax call otherwise some javascript functions will not work ..
Your render call should be something like this
$this->renderPartial('ajaxindex',array('dataProvider'=>$dataProvider),false,true);
Refer this page for more info http://www.yiiframework.com/doc/api/1.1/CController#renderPartial-detail
You should also use renderPartial if updating a div only, render will call layout files as well.
Related
I'm showing a loading bar before the content loads successfully. And after load I am displaying the content by jQuery but when i visit the page first time the loader is showing forever and the on load event isn't firing. It fires when i manually refresh the page. What's wrong with my code?
Event call code:
$(window).on('load', function(){
$("#slider-pre-loader").fadeOut("slow");
$("#video-blog-slider").fadeIn();
});
Dynamic HTML:
<div id="slider-pre-loader"></div>
<div id="video-blog-slider" style="display: none">
<div class="blog-category-items blog-page" id="blogIndex">
<div class="container">
<?php
$hpos = 0;
foreach ($categories as $category):
$categoryhref = fakeUrl::genSlugFromText($category['name']);
$listVideos = $category['videos'];
if (in_array($category['name'], $categoryDisplay)) :
?>
<div class="blog-groups">
<div class="group-heading">
<h3>
Test title
</h3>
</div>
<?php if ($category['desc'] != '') :?>
<p class="group-desc"><?php echo $category['desc'];?></p>
<?php endif;?>
<?php
$slideClass = '';
if (!$detect->isMobile() && !$detect->isTablet() ) {
$slideClass = 'blog-slider';
}
?>
<div class="<?php echo $slideClass;?> owl-lg-dot mb-none owl-theme owl-loaded" id="videoList">
<?php
$v = 0;
foreach ($listVideos as $video) :
$v++;
$itemClass = '';
if (($detect->isMobile() || $detect->isTablet()) && $v > 5) {
$itemClass = 'item-disable';
}
$videoSlug = fakeUrl::genSlugFromText($video['title']);
?>
<div class="blog-item <?php echo $itemClass;?>">
<div class="blog-image">
<a href="/blog/<?php echo $videoSlug; ?>" title="<?php echo $video['title'];?>">
</a>
</div>
<div class="caption">
<a class="blog-list-video-title" href="/blog/<?php echo $videoSlug; ?>" title="<?php echo $video['title'];?>">
</a>
</div>
<div class="blog-metas">
<small class="blog-views"><?php echo number_format($video['views']); ?> views</small>
</div>
</div>
<?php
endforeach;
?>
</div>
</div>
<?php
endif;
endforeach;
?>
</div>
</div>
</div>
jQuery placed before event call:
<script src="//code.jquery.com/jquery-1.11.3.min.js" async></script>
Don't place async attribute on your script tags unless you really need your script file to be loaded asynchronously. Right now, your 'jQuery' code is being loaded asynchronously, i.e. jQuery is most probably not loaded when you are trying to attach your event.
The only explanation for it working the second time upon manual refresh is that the browser is 'synchronously' loading the cached resource. Different browsers do this differently, so you can expect inconsistent behaviour there.
Just remove the async attribute, and you should see your event firing every time.
The $(window) selector is for selecting the viewport whereas the $(document) selector is for the entire document (that is, what's inside the <html> tag).
Try using the following:
$(document).on('load', function(){
$("#slider-pre-loader").fadeOut("slow");
$("#video-blog-slider").fadeIn();
});
I hope this working with you, I have created example you will be woking with document.ready it means JQuery see and focus on all elements in your web page, here is fiddle
Simple for test
<div id="slider-pre-loader">no</div>
<div id="video-blog-slider" style="display: none">
hi
</div>
OR your code
<div id="slider-pre-loader">no</div>
<div id="video-blog-slider" style="display: none">
<div class="blog-category-items blog-page" id="blogIndex">
<div class="container">
<?php
$hpos = 0;
foreach ($categories as $category):
$categoryhref = fakeUrl::genSlugFromText($category['name']);
$listVideos = $category['videos'];
if (in_array($category['name'], $categoryDisplay)) :
?>
<div class="blog-groups">
<div class="group-heading">
<h3>
Test title
</h3>
</div>
<?php if ($category['desc'] != '') :?>
<p class="group-desc"><?php echo $category['desc'];?></p>
<?php endif;?>
<?php
$slideClass = '';
if (!$detect->isMobile() && !$detect->isTablet() ) {
$slideClass = 'blog-slider';
}
?>
<div class="<?php echo $slideClass;?> owl-lg-dot mb-none owl-theme owl-loaded" id="videoList">
<?php
$v = 0;
foreach ($listVideos as $video) :
$v++;
$itemClass = '';
if (($detect->isMobile() || $detect->isTablet()) && $v > 5) {
$itemClass = 'item-disable';
}
$videoSlug = fakeUrl::genSlugFromText($video['title']);
?>
<div class="blog-item <?php echo $itemClass;?>">
<div class="blog-image">
<a href="/blog/<?php echo $videoSlug; ?>" title="<?php echo $video['title'];?>">
</a>
</div>
<div class="caption">
<a class="blog-list-video-title" href="/blog/<?php echo $videoSlug; ?>" title="<?php echo $video['title'];?>">
</a>
</div>
<div class="blog-metas">
<small class="blog-views"><?php echo number_format($video['views']); ?> views</small>
</div>
</div>
<?php
endforeach;
?>
</div>
</div>
<?php
endif;
endforeach;
?>
</div>
</div>
</div>
Javascript:
$(document).ready(function() {
$("#slider-pre-loader").fadeOut('slow');
$("#video-blog-slider").fadeIn('slow');
});
slightly varied question but I have a script that runs and gets data from a mysql db. The end result shows them as buttons, when i click the buttons it gives me an alert with the correct id number correspsonding to whats selected, but when i try to put that into a textfield is isnt the same, its basically the last in the mysql? WHy would the alert show the correct and the updated textfield so totally different information??
The working php that alerts the correct info is :
<?php
include('config.php');
$action = $_REQUEST['action'];
if($action=="showAll"){
$stmt=$dbcon->prepare('SELECT product_id, product_name FROM products ORDER BY product_name');
$stmt->execute();
}else{
$stmt=$dbcon->prepare('SELECT product_id, product_name FROM products WHERE cat_id=:cid ORDER BY product_name');
$stmt->execute(array(':cid'=>$action));
}
?>
<div class="row">
<?php
if($stmt->rowCount() > 0){
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
?>
<div class="col-xs-3">
<div style="border-radius:3px; border:#cdcdcd solid 1px; padding:22px;"><button type="button" class="btn btn-default" onclick="alert('<? echo $product_id; ?>')"><?php echo $product_name; ?></button></div><br />
</div>
<?php
}
}else{
?>
<div class="col-xs-3">
<div style="border-radius:3px; border:#cdcdcd solid 1px; padding:22px;"><button type="button" class="btn btn-default" onclick="alert('<? echo $product_id; ?>')"><?php echo $product_name; ?></button></div><br />
</div>
<?php
}
?>
</div>
<div>
text : <input id="textField1" type="text" value="0" align="right" size="13"/><br>
</div>
<script>
function display()
{
document.getElementById("textField1").value = "<? echo $product_name; ?>";
}
</script>
But if change the button to use the 'display script' it just shows last in database?
I have traveled many articles Stack OverFlow but none have solved my problem. I just want to use Ajax with Cake php to refresh a DIV containing the results of my pagination.
Note:
I included the jQuery library.
I called the RequestHandler component:
public $components = array('RequestHandler');
public function beforeFilter() {
if($this->RequestHandler->isAjax()){
$this->layout=null;
Configure::write('debug', 0);
}
}
I checked the presence of a "ajax.ctp" in the layout folder
Here is my search function:
public function searchIndex(){
//debug($this->request->data); die;
$search = $this->request->data['Concessionnaire']['search'];
$this->Paginator->settings = array(
'conditions' => array('Concessionnaire.ville LIKE' => '%'.$search.'%'),
'limit' => 5
);
$data = $this->Paginator->paginate('Concessionnaire');
$this->set('concessionnaires', $data);
$this->render('index');
}
Views :
<div class="row">
<div class="large-12 columns">
<div class="panel">
<h4>Recherchez une ville :</h4>
<?php echo $this->Form->create('Concessionnaire',array('id' => 'textBox', 'type' => 'post','url' => array('controller' => 'concessionnaires', 'action' => 'searchIndex'))); ?>
<?php echo $this->Form->input('search', array('label'=>"",'placeholder'=>'Tapez le nom d\'une ville, puis la touche Entree de votre clavier' ,'id'=>'search')); ?>
<?php echo $this->Form->end(); ?>
</div>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<div class="panel" id="conssR">
<!-- generation vignettes -->
<?php foreach ($concessionnaires as $concessionnaire): ?>
<div class="panel conssPanel radius">
<h4><b><?php echo h($concessionnaire['Concessionnaire']['nom']); ?></b></h4>
<div class="row">
<div class="large-6 columns" style="padding-left: 70px; font-size: 20px;">
<?php echo h($concessionnaire['Concessionnaire']['adresse']); ?><br>
<?php echo h($concessionnaire['Concessionnaire']['cp']); ?>
<?php echo h($concessionnaire['Concessionnaire']['ville']); ?>
<!-- <p>It's a little ostentatious, but useful for important content.</p> -->
</div>
<div class="large-6 columns" style="font-size: 20px; text-align: center;">
Tel: <?php echo h($concessionnaire['Concessionnaire']['tel']); ?><br>
Site: <?php echo h($concessionnaire['Concessionnaire']['website']); ?>
</div>
</div>
<?php
// $map_id = "map_canvas";
// $marker_id = 1;
// $position = "rue du depot, 62000 ARRAS";
// echo $this->GoogleMap->addMarker($map_id, $marker_id, $position);
?>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
I want to reload the DIV "#conssR" with the string results entered in the form "Concessionnaires". For now , when i write something and valid, the controller show me the result by refreshing the page but I just want to recharge the DIV.
Thank you in advance for your help
$this->Paginator->options(array(
'update' => '#conssR',
'evalScripts' => true
));
The code above is not part of function it is part of view files which are in View folder and it creates the proper JavaScript to update the div.
Check : http://book.cakephp.org/2.0/en/core-libraries/helpers/paginator.html
It is a helper and helper code goes in your view
if($this->request->is('ajax'))
{
$this->render('/Elements/ajax');
}
The above code is used to render ajax.ctp in View/Elements folder which you are not doing at the moment.
I am actually stucking up with this problem for a day.I just want to perform edit operation on this script.My main page which is called customer-grid-screen.php
the code comes as follows
<?php include("header.inc.php");
include("left.inc.php");
include('config.php');?>
<div id="page-content-wrapper">
<?php include("pagetitile.inc.php"); ?>
<div id="page-content">
<div class="clearfix mrg10B"><span class="button-content">Add</span></div>
<div class="example-box">
<div class="example-code">
<table class="table table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Details</th>
<th>Domain</th>
<th>Vertical</th>
<th>Taxanomy</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
$result = mysql_query("SELECT * FROM customer_mast ORDER BY customer_id") or trigger_error(mysql_error());
while($row = mysql_fetch_array($result)){
if($row<1) {
echo "</tr>";
echo "<tr>";
echo "<td colspan='6' class='text-center pad25A'>No Record</td>";
echo "</tr>";
}
else
{
foreach($row AS $key => $value){
$row[$key] = stripslashes($value);
}
echo "<tr>";
echo "<td><a href='customer-screen.php'>" . nl2br( $row['customer_name']) . "</td>";
if(!empty($row['customer_details'])){
echo "<td><a href='customer-screen.php'>". nl2br( $row['customer_details']) . "</td>";
}
else{
echo "<td><a href='customer-screen.php'>-</td>";
}
if(!empty( $row['domain']))
{
echo "<td><a href='customer-screen.php'>". nl2br( $row['domain']) . "</td>";}
else{
echo "<td><a href='customer-screen.php'>-</td>";
}
if(!empty($row['vertical'])){
echo "<td><a href='customer-screen.php'>". nl2br( $row['vertical']) . "</td>";}
else{
echo "<td><a href='customer-screen.php'>-</td>";
}
if(!empty($row['taxanomy'])){
echo "<td><a href='customer-screen.php'>". nl2br( $row['taxanomy']) . "</td>";
}
else
{ echo "<td><a href='customer-screen.php'>-</td>";}
echo $row['customer_id'];
echo "<td>
<a href='javascript:?id={$row['customer_id']}' data-id={$row['customer_id']} class='btn small bg-blue-alt tooltip-button modal-customeredit' data-placement='top' title='Edit'><i class='glyph-icon icon-edit' ></i>
</a>
<a href='customer_delete.php?id={$row['customer_id']}' class='btn small bg-red tooltip-button confirm' data-placement='top' title='Remove'><i class='glyph-icon icon-remove'></i>
</a>
</td>";}}
?>
</tbody>
</table>
</div>
</div>
</div><!-- #page-content -->
</div>
</div>
<?php include("footer.inc.php"); ?>
I have to perform edit operation through modal pop up.i implemented the code as follows.
footer.inc.php
------------
<!-- Project Edit MAINLY SEE THIS-->
<div class="hide" id="modal-projedit" title="Edit Project Info">
<div class="pad10A">
<h3>Edit Project Info</h3>
<p class="font-gray-dark"> Fides Admin uses colors & styles from both the default theme color schemes and the included core color helpers. </p>
<div class="divider mrg25B"></div>
<form id="project-edit" action="" class="col-md-12 center-margin" method="">
<div class="form-row">
<div class="form-label col-md-3">
<label for="name">
Project Name:
<span class="required">*</span>
</label>
</div>
<div class="form-input col-md-9">
<input id="name" name="name" placeholder="Name" data-required="true" class="parsley-validated" type="text">
</div>
</div>
<div class="divider"></div>
<div class="form-row">
<div class="form-input col-md-8 col-md-offset-3">
<a href="javascript:;" class="btn medium primary-bg radius-all-4" id="project-edit-valid" onclick="javascript:$('#project-edit').parsley( 'validate' );" title="Validate!">
<span class="button-content">
Update
</span>
</a>
</div>
</div>
</form>
</div>
</div>
//modal window script:
$( ".modal-customeredit" ).click(function() {
var myGroupId = $(this).data('id');
alert( myGroupId); //i can able to alert the paricular row id i want to edit i dont know to pass it through php.
$( "#modal-customeredit" ).dialog({
modal: true,
minWidth: 700,
minHeight: 200,
dialogClass: "modal-dialog",
show: "fadeIn"
});
$('.ui-widget-overlay').addClass('bg-black opacity-60');
});
//same page php file
<?php
$id=???; (get id not working)
$sql="SELECT * FROM `customer_mast` where customer_id='$id'";
$result=mysql_query($sql);
if($result==false)
{
die(mysql_error());
}
else{
$row = mysql_fetch_array($result);}
if (isset($_POST['submit'])){
foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); }
$sql = "UPDATE `customer_mast` SET `customer_name` = '{$_POST['customer_name']}' , `customer_details` = '{$_POST['customer_details']}',`domain` = '{$_POST['domain']}' ,`vertical` = '{$_POST['vertical']}' ,`taxanomy` = '{$_POST['taxanomy']}' WHERE `customer_id` = '$id' ";
mysql_query($sql) or die(mysql_error());
echo (mysql_affected_rows()) ? "Edited row.<br />" : "Nothing changed. <br />";
header("Location:customer-grid.php");}
?>
Can anybody please explain me how i can pass that id value to the php script on same page and peform my edit operation.I can explain more if you have doubts,I have gone through many things to to make it correct.Nothing helped me.Please give your suggestion.
You should see how AJAX is working to pass a value to PHP.
$( "#modal-customeredit" ).dialog({
modal: true,
minWidth: 700,
minHeight: 200,
dialogClass: "modal-dialog",
show: "fadeIn"
buttons: {
Edit: function() {
// Sample ajax request ( see the documentation)
$.ajax({
type: "POST",
url: "request.php",
data: { id: myGroupId }, // data retrieve on server-side ($_POST['id'])
dataType : 'html|json|...' // expected data returned
})
.success(function( msg ) {
alert( "Data Saved: " + msg );
});
},
Cancel: function() {
$( this ).dialog( "close" );
}
}
// stop event when form is submit
return false;
});
You have all the element to do it by yourself. Just one more advice, try to separate your files. For instance execute your treatment in another file as request.php.
Edit :
Sample for your request.php (I will return json).
<?php
header('Content-type: application/json'); // Tell the app that you want return json
$id= $_POST['id']; // correspond to your retrieved data in ajax function
// ... Your SQL request and other treatment
// The result return
echo json_encode($result);
?>
The data are now send back to your ajax function in .success( data ).
i want to block certain searches from my search box....the address looks like this below:
http://domain.com/search.php?search=dog
How do i set up an array or something that blocks the search word "dog"?
<form id="headbar-search" action="search.php" method="GET" x-webkit-speech="x-webkit-speech">
<input type="text" name="search" id="jsid-search-input" value="<?php echo$_GET['search']; ?>" class="ui-autocomplete-input search search_input" placeholder="Search…" tabindex="1"/>
<div class="ui-widget"></div>
</form>
search.php
<?php include 'header.php'; ?>
<!-- Container -->
<div id="container">
<div class="left">
<div class="pic" style="overflow:hidden; margin-top:5px;">
<div style="margin:0 0 5px 0;overflow:hidden;border:none;height:auto;">
<div class="video-container" style="text-align: left; background: #fff;">
<h2>Search results for: <?php echo htmlspecialchars($_GET['search'], ENT_QUOTES, 'UTF-8'); ?></h2>
________________________________________________________________________________________
<br><br>
<?php
if($svid) {
$squerys = mysql_query("SELECT * FROM videos WHERE title LIKE '%$word%' OR author LIKE '%$word%'");
while($ft = mysql_fetch_array($squerys)){
?>
<table>
<tr>
<td>
<?php if($st['seo'] == 1) { ?>
<a href="./<?php echo seo($ft['title'], $ft['id']); ?>.html">
<?php }else{ ?>
<a href="./?v=<?php echo$ft['id'];?>">
<?php } ?>
<div class="image-container"><img src="<?php echo$ft['thumb_large']; ?>" width="120" height="130"></div></a></td>
<td style="padding-left:10px; vertical-align:top;"><h3>
<?php if($st['seo'] == 1) { ?>
<a href="./<?php echo seo($ft['title'], $ft['id']); ?>.html">
<?php }else{ ?>
<a href="./?v=<?php echo$ft['id'];?>">
<?php } ?>
<?php echo stripslashes($ft['title']); ?></a></h3>By: <?php echo$ft['author']; ?><br><?php echo number_format(round($ft['views'])); ?> views</td>
</tr>
<br>
</table>
<?php
}
}else{
echo"No results found.";
}
?>
</div>
<div style="margin: 5px 0 0 0;"></div>
</div></div>
</div>
<?php include 'sidebar.php'; ?>
<div class="clear"></div>
</div>
<!-- Container -->
<?php include 'footer.php'; ?>
A very quick markup
$Naughty_Words = array ("Cat","dog");
function DetermineBanned ($Input,$Array){
if (in_array($Input,$Array)){
return true;
}
return false;
}
var_dump(DetermineBanned("Cat",$Naughty_Words)); // Returns bool(true)
var_dump(DetermineBanned("dd",$Naughty_Words)); // Returns bool(false)
var_dump(DetermineBanned("CatMan",$Naughty_Words)); // Returns bool(false)
var_dump(DetermineBanned("CatMan",$Naughty_Words)); // bool(false)
var_dump(DetermineBanned("CatDog",$Naughty_Words)); // bool(false)
/// Due to the lack of initial code being shown in your question, I have spotted a bug, it's up to you to decide how to make it fool proof
//Validate with
if (DetermineBanned($_GET['Key'],$Naughty_Words) !== false){
echo "Banned Words Detected";
exit;
}
It has to be done in the search.php file.
Example:
$excluded_words = array("dog", "hello", "world");
if(in_array($_GET['search'], $excluded_words) {
echo "Keyword not found";
}
Note: this is just if you pass one word only
Put some javascript between your html and php.
<form>
<input type="text" id="search-box" value="" placeholder="Search…"/>
<input type="submit" onclick="search()"/>
</form>
javascript
var badWords = ["dog"];
function search() {
var searchStr = document.getElementById("search-box").value;
var badWordHit = false;
for (key in badWords) {
if (badWords[key] == searchStr) {
badWordHit = true;
}
}
if (badWordHit) {
alert("I ain't searchin' for no dog");
} else {
alert("searching");
// do ajax request here
}
}