iranianpep / ajax-live-search Goto Github PK
View Code? Open in Web Editor NEWAJAX Live Search is a PHP search form that similar to Google Autocomplete feature displays the result as you type.
License: MIT License
AJAX Live Search is a PHP search form that similar to Google Autocomplete feature displays the result as you type.
License: MIT License
We have several existing forms that are using the live search, and they all have form action = "get" ... not "post". When a form is finally submitted, it seemed to be using the post methodology rather than get since the data isn't being passed in the form my_page.php?my_variable=X. IOW, no variables are being submitted with the form.
However, I've discovered that the data selected by the user in the live search isn't passed at all when the form is submitted. I've tried this with both post and get methodologies, and even tried removing a JavaScript function from being invoked (that I'd written some years ago) which validated the format of the data being entered.
Also, there are two different forms on the page that invoke live search. Could this somehow be related? My hunch is it isn't.
Finally, two other modifications I've made that are worth mentioning:
I've attached a screen shot of all of the moving parts for our integration as it now stands. Do please let me know if there's any other information I can pass on to make troubleshooting easier.
I'll look forward to hearing from you with anticipation!
Call to a member function prepare() on a non-object in /var/sites/s/smashk.co.uk/public_html/liv/core/Handler.php on line 123
is the responce on resource tool and then on display ..
Something went wront. Please refresh the page. .. the database works with other apps.. fine..like databasedapp please help.
thankyou
Hi!
Let's say we want to search for "cole" from a column, but instead we write "ole". This live search will not suggest you "cole" (with the "ole" bolded) as many live-search plug ins would. So is there a way to enable this feature on this live search by maybe changing the search pattern?
I've attempted to modify the handler in multiple different ways for natural language mode, with limited success.
Ultimately I'm looking for my $whereClause to look like:
MATCH(Car_Type) AGAINST(':query{$counter}' IN BOOLEAN MODE)
But it seems PDO is fouling up the search, because if in the $whereClause I simply insert $query:
MATCH(Car_Type) AGAINST('$query' IN BOOLEAN MODE)
It searches in natural language mode, but that also opens the site up for attack. Any suggestions would be very helpful, PDO is completely new to me.
Thank you!
Hello,
I tried to join tables but it does not work. I think that there might be problem in type of tables because they have similar structure. I have 2 tables with these columns (ID, name, ....).
Do you think is there any way I can make this works?
Tried with JOIN and UNION solutions I found on stackoverflow.
I just upgraded to php7, unfortunately this broke the livesearch script.
I'm getting this error in the apache log:
[Sat Sep 03 21:27:07.827993 2016] [:error] [pid 21637] [client 172.17.111.111:62894] PHP Fatal error: Uncaught Error: Call to a member function prepare() on null in /var/www/iamhungry/core/Handler.php:178\nStack trace:\n#0 /var/www/iamhungry/core/Handler.php(120): AjaxLiveSearch\core\Handler::getDataFromMySQL(Array, 'a', 1, 5)\n#1 /var/www/iamhungry/ajax/process_livesearch.php(39): AjaxLiveSearch\core\Handler::getResult('ls_query', 'a', 1, 5)\n#2 {main}\n thrown in /var/www/iamhungry/core/Handler.php on line 178, referer: http://heiweb06/iamhungry/
I like the script but he search only in first word in the row. How can i make it to search in all words from every row from database.
Hi,
How can i change the font of the result?
I have tried changing every font name in every css file without any result!
Hi,
I have the following problem.
I placed this ajax live search inside a form.
Then I created an input field with type text. This is the field where I use this ajax live search function - when I click to this input field and start typing, the results are showing and when I click to one, it is being written into this field. Seems it works like a charm.
But here comes my issue, after I submit this form, the input field's $_POST value doesn't exist. I got a php notice: Notice: Undefined index: ...
My question is, how should I keep the $_POST value of this input field after I submit the form?
Thank you in advance!
I have mysql database and I am making it's sphinx real time indexes to provide fast search.
can I use ajax_live_search with my index to provide auto suggestions?
How do I choose which data will be defined in the input value after selecting the item that comes from ajax response?
Look at my page:
http://tisaudavel.com/animalWiki/
Place the word "sir" in the search when selecting any opรงรตa, rather than the input catch the first query value, he takes the second. I need you to take the first.
hello sir, I just downloaded and setup what you have created.
It's working like booommm.
but in my case I don't want to display whole table row in suggestion.
I just want to show movie title in my search suggestion, how can I do that.?
One more thing if any how I can do that how can I redirect on other page if user click on any of name suggestion.?
Please let me know.
Thank you.
Hello,
this is really good search engine. I implemented this and search works well for one table, but I am interested is it possible to implement this search to search through multiple tables?
Is it possible to search multiple Mysql Tables querying only one search field ?
Thanks
Hi!
I would like to exclude some data from the search depending on what option is choosen.
Ex:
SELECT column1, column2 FROM table WHERE column1 ='$variablechoosen' AND column2 LIKE '$userinput';
How would that look like in your awesome program?
I just loaded ALS but I am having a hard time finding the posted form field.
I added a name attribute but it still isn't found until I removed the class='MySearch' attribute.
I am using the index.php file supplied.
I connected successfully to my database and it correctly displays my field options.
Any suggestions?
Thanks!
Hello Friend,
Sorry for the simple question, but my knowledge js is still somewhat limited and decided to turn to you.
You have some code ready for use at the event I enter key?
I want to direct the value of the input field to another page, but can not make it through form, I believe we have to do this via js same, but I could not.
Hi ,
Could please confirm if root access is required to the database to make this script work?
Thank you
Kind Regards
Hi All,
First thanks for this brilliant code, love it. I have been playing with it for the last 3 days ๐
I m trying to trick the code to bring the possibility of multi word search, in principle it s seems simple but I haven't nailed it yet.
It would mean exploding the $query variable and then run an Intersect with the different queries generated.... but I m failing on this..
1- Is it a functionality intended to be present in the code? I mean from the home page example http://ajaxlivesearch.com/ the query "Aaron Mason" would return me an example, but only "Aaron" returns something
2- Any workaround about it (example)? it seems that PDO is a bit allergic to INTERSECT...
thanks
Alex
Hi,
The current version of the process_livesearch.php file should probably be updated with "else if" conditions. Otherwise all the validation process and the ajax response in case of failure are not accurate (it would only trigger an ajax error due to parsing error instead of the real failure tested by validation functions following an "ajax success").
On top of that, without those "else if" instead of "if" the "try" will still be fired even if the previous validation have failed.
i would recommend to update the file like this
use AjaxLiveSearch\core\Handler;
header('Access-Control-Allow-Origin: http://xxxxxxxx');
header('Access-Control-Allow-Methods: *');
header('Content-Type: application/json');
file_exists(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'Handler.php')) ? require_once realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'Handler.php') : die('There is no such a file: Handler.php');
// 1. Validate all inputs
$errors = Handler::validateInput($_POST);
if (!empty($errors)) {
// Required inputs are not provided
Handler::formResponse('failed', 'Error: Required or invalid inputs: ' . implode(',', $errors));
}
// 2. A layer of security against those Bots that submit a form quickly
else if (!Handler::verifyBotSearched($_POST['ls_page_loaded_at'])) {
// Searching is started sooner than the search start time offset
Handler::formResponse('failed', 'Error: You are too fast, or this is a Bot. Please search now.');
}
// 3. Verify the token - CSRF protection
else if (!Handler::verifySessionValue('token', $_POST['ls_token']) ||
!Handler::verifySessionValue('anti_bot', $_POST['ls_anti_bot'])
) {
// Tokens are not matched
Handler::formResponse('failed', 'Error: Please refresh the page. It seems that your session is expired.');
}
else {
try {
// 4. Start looking for the query
$result = json_encode(Handler::getResult(
$_POST['ls_query_id'],
$_POST['ls_query'],
(int)$_POST['ls_current_page'],
(int)$_POST['ls_items_per_page']
));
} catch (\Exception $e) {
$catchedError = $e->getMessage();
}
if (empty($catchedError)) {
// 5. Return the result
Handler::formResponse('success', 'Successful request', $result);
} else {
Handler::formResponse('failed', $catchedError);
}
}
Best regards,
Laurent
Hi,
Thanks for a great script.
I need some help on the next step. I have got it to display the results but I need it to open another file using GET or POST when one of the results in the list is clicked with a value passed (say ID value).
I have got the variable by adding 'var myid = jQuery('.mySearch').val(selectedOne);' and now want to open 'searchresults.php?myid='.$myid when the user clicks on one of the results without having to press enter.
Can you help?
Thanks
TT
Hello,
Until v3, I used to use "ls_hide" custom class for one of my result column.
Since your new code structure, I didn't find how to reuse it?
I have to display this column in my filter result to call it as GET variable, however I would like to hide it.
Could you please help me solve this problem?
Thanks,
1)I have an image file location(image 'src') on my data base. How I can show this image on search field?
2) script.js is not in the zip file.
Thanks
Hello, thank you for your work and for sharing it for free. I want to change the style of the input box, but when i am in the css folder, event when i delete it or modifiy any file, nothing is happening when i refresh the "index.php". Can someone help to find how to change it ? thanks.
We have several existing forms that are using the live search, and they all have form action = "get" ... not "post". When a form is finally submitted, it seems to be using the post methodology rather than get since the data isn't being passed in the form my_page.php?my_variable=X. IOW, no variables are being submitted with the form.
How specifically do I fix this?
Shine on,
M
Hi,
I have tried to create a dictionary with this search engine. But i cant get it going.
I want to create something like this.
http://apps.timwhitlock.info/emoji/tools/finder#1f61a
Can you please guide me?
-Mohsen
Hi,
Please, How to configure Ajax Live Search for dont use Case Sensitive on Search?
Example: Using LIKE on mysql consult and don't Where.
Hi,
I have been trying to find out where I can add a custom WHERE to the sql for a while now but I have no idea really where to put it.
So the thing is that I will use this script in my inventory, in the table where all articles are I have a column with organization which is bound to the customer eg. organization='test'. This makes it possible for me to only view one specific customer since all my customer(s) articles are stored in one table.
Please help me where I should add this! :)
Hey guys, I need to create a column that contains "Edit" and "Delete" of the records. Is a simple button with PHP or HTML, but I don't know where is the file that contains the custom HTML or PHP.
I can't create a SQL with the button, people said me this and I'm not allowed to do that.
Only JS, PHP or HTML.
Thanks. Greetings!
Hello! :D Love your script, man! However, is it possible to search for combinations of letters inside a word? For instance "thu" inside "arthur"?
Cheers :)
There seems to be no form except the comment in case of the <!search form demo> in the index.php file. Where can I find the form?
When I load the search.php into a div in another page ,in IE I don't have any problem,But
in Google Chrome, the search results showed on the left side of the page instead of under search input.Any idea why?I have used the jquery (.load) function.
thanks
onResultClick is not working when I just filter 1 column
Hi, is it possible de to search through different table with an OR condition while typing ?
Hello,
I have changed the maxInputLength to 40, where default is 20 in the config file. When I use the search it is still restricted as 20, even though when I echo the variable as text it says 40. What am I doing wrong?
Hi,
When i have 5 or 6 tables and text in all of the they stack on each other. Is it because of css file? How can it be solved?
Hi, i need to genarate the loaded_at and token (required) from jquery. How can i do this? practically genarate this:
$token = Handler::getToken(); $time = time(); $maxInputLength = Config::getConfig('maxInputLength');
via jquery.
Thanks
Hello.
I have installed on my server "SB Admin 2".
I don't know why when I load the page, the search engine appears like this:
The JS that works in that is this:
result.css({left: query.position().left + 1, width: query.outerWidth() - 2});
The "Left" value must be 158 barely, but in the load is set on 1 (0 in default, null)
When I resize the window, all works perfectly, with this
$(window).resize(function () { //adjust_result_position(); result.css({left: query.position().left + 1, width: query.outerWidth() - 2}); });
But I want it dinamically and not only on resize.
Like this:
I hope you can help me,
Greetings
I'm unable to select the answer with the enter button. Otherwise it is a cracking piece of software. I absolutely love it. If possible are you able to please fix it as I really need it to have support for the enter button. I have been trying to do it myself with no luck :) ๐ ๐ฏ ๐ฑ
Hi
I am using this script in a German Website, Things worked fine on Localhost (wamp server) But when i uploaded it to a live web-server it displays strange characters in Search-Results
http://coolkochen.sevensigil.com/NJK3/livesearch/index.php
Best Regards
Nasir
Question:
Hi,
I have been trying to find out where I can add a custom WHERE to the sql for a while now but I have no idea really where to put it.
So the thing is that I will use this script in my inventory, in the table where all articles are I have a column with organization which is bound to the customer eg. organization='test'. This makes it possible for me to only view one specific customer since all my customer(s) articles are stored in one table.
Please help me where I should add this! :)
Answer:
Hi,
The sql query is formed in getDataFromMySQL function in line 137 of core/Handler.php
Question:
Hi,
Unfortionatly i would really need a little more information, where in the function should I add my custom Where organization='test'?
How should the syntax and/or code be modified to accommodate more than one instance of the form on the same page?
Is there a way to search multiple tables ?
I have integrated ajax live search code in my project but it doesn't work... and do nothing..
Anybody please Help me...
Thank you in advance
I've run into a problem with desktop v. mobile forms executing the way I've intended for them to be. Specifically, for the desktop version, everything functions properly; however, for the mobile version, results are displayed properly, but the onClick functionality doesn't work in that when a specific result is selected, nothing happens -- the result doesn't load in the text input box.
Specifically, I've got code something like this (at least while I'm troubleshooting):
...
<!-- Desktop -->
<div class="hidden-xs">
<input type="text" name="model_number" id="ls_query" class="form-control mySearch" placeholder="Desktop world ...">
</div>
<!-- Mobile -->
<div class="visible-xs">
<input type="text" name="model_number" id="ls_query_2" class="form-control mySearch" placeholder="Mobile world ...">
</div>
...
<script type="text/javascript" src="/AjaxLiveSearch/js/ajaxlivesearch.js"></script>
<script>
jQuery(document).ready(function(){
jQuery(".mySearch").ajaxlivesearch({
loaded_at: <?php echo time(); ?>,
token: <?php echo "'" . $handler->getToken() . "'"; ?>,
max_input: <?php echo Config::getConfig('maxInputLength'); ?>,
onResultClick: function(e, data) {
// get the index 0 (first column) value
var selectedOne = jQuery(data.selected).find('td').eq('0').text();
// set the input value
jQuery('#ls_query').val(selectedOne);
// hide the result
jQuery("#ls_query").trigger('ajaxlivesearch:hide_result');
},
onResultEnter: function(e, data) {
// do whatever you want
// jQuery("#ls_query").trigger('ajaxlivesearch:search', {query: 'test'});
},
onAjaxComplete: function(e, data) {
}
});
})
</script>
Aside: The responsive functionality doesn't work out of the box, so I've resorted to using two different forms which result in two separate queries being executed so that I can have more information being displayed in the desktop version than is displayed in the mobile version.
Note: I'm also concerned about what's going to happen when two separate forms will need to be loaded on the same page.
I look forward to hearing from you with anticipation,
M
Has this ever been implemented on wordpress? do you have any suggestions?
Ive been trying at this for a few days now with very little progress.
"something went wrong. please refresh the page"
I do get to the point of being able to type in a search, the loader icon shows up, with the resulting error above.
I got this far once i changed the link locations within index.php that is in the new directory IE: ../folder/config.php ../folder/handler.php etc etc. but im stuck now.
{SOLVED}
(REASON: OVERSIGHT FROM WORKING LATE AT NIGHT)
FOR ANYONE THAT COMES TO THE SAME PROBLEM:
SOLUTION: Update the url in the ajaxlivesearch.js and ajaxlivesearch.min.js files.
Great Program, thank you for sharing!
The problem is when i click on a result nothing happens. I want to send a query and show a result page when i click on the result. Before i included the ajaxlivesearch funtion i just typed in a keyword and pushed enter and then my result page showed up, this happens with an query. But after i included the ajaxlivesearch funtion pressing enter was not an option anymore, nothing happens.
There's a bug in the module.
To recreate try searching (even at the demo page) for only digits with the number being more than MAX_INPUT_LENGTH.
The bug sits in function validate_input (at line 57).
Changing this
elseif ($k === 'ls_query' && $v > Config::MAX_INPUT_LENGTH)
to
elseif ($k === 'ls_query' && strlen($v) > Config::MAX_INPUT_LENGTH)
solves the issue.
Thanks!
P.S.: Otherwise great search module that has many advantages over alternatives: keyboard control and config flexibility is a must for me.
Regards,
Eugene
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.