Coder Social home page Coder Social logo

iranianpep / ajax-live-search Goto Github PK

View Code? Open in Web Editor NEW
245.0 28.0 80.0 207 KB

AJAX Live Search is a PHP search form that similar to Google Autocomplete feature displays the result as you type.

License: MIT License

PHP 45.51% CSS 8.44% JavaScript 46.05%
ajax search ajax-live-search php jquery jquery-plugin javascript auto-complete

ajax-live-search's People

Contributors

antarasi avatar ehsanabbasimov avatar iranianpep avatar mikerissi avatar vw1302 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ajax-live-search's Issues

3) Form submission with GET action

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:

  1. We were already using an updated version of jQuery (v.1.13), so the version bundled with the live search code isn't being called.
  2. We will be using live search in a number of different areas of the site, so I've uploaded the code into one central directory on the server, and I've modified the paths in the live search code to point to this central location.

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!

Shine on,
M
screen-shot-2016-10-20-at-1 57 30-pm

Wont load result..

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

Search within a "String" of a Column

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?

Searching in Natural Language Mode

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!

Multiple tables search

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.

PHP7 compatibility

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/

Search only in first word

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.

Change the font

Hi,

How can i change the font of the result?
I have tried changing every font name in every css file without any result!

Problem with $_POST result after form submission

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!

set value on input

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.

use li instead of table for showing live suggestion

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.

How to search through different tables?

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?

Something went wrong. Please refresh the page.

I keep getting the above message when trying to use the script. It is not producing an error_log so not sure what the actual issue is? My MySQL details are correct and same with the database information.

Any help will be appreciated.
capture

Exlude data from search

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?

Cannot find POSTed field

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!

Submit info

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.

Root Access issue

Hi ,

Could please confirm if root access is required to the database to make this script work?

Thank you

Kind Regards

Sorry again still nto working .. :(


Strict Standards: Non-static method AjaxLiveSearch\core\Handler::getDataFromMySQL() should not be called statically in /var/sites/s/smashk.co.uk/public_html/check/core/Handler.php on line 122
{"status":"success","message":"Successful request<\/td><\/tr>","result":"{\"html\":\"There is no result for \\"123124\\"<\\/td><\\/tr>\",\"number_of_results\":0,\"total_pages\":1}"}

Multiple Words search

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

Security issue in process_livesearch.php

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

Send result on click

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

CustomClass (ls_hide)

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,

Show image on search field

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

changing css style for position

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.

3) Form GET action

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

How to search no Case Sensitive

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.

Adding a custom 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! :)

How can I create a new custom column with HTML or PHP?

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!

Load search.php into a div in another page

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

Search multiple table

Hi, is it possible de to search through different table with an OR condition while typing ?

Issue regarding maxInputLength

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?

Change the width of result box

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?

Generate loaded_at and token and maxInput from jquery

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

*FIXED* query.position().left is not working properly

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:

a38e044511e8a79d9c3a3dba4271faa7

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)

12ffcd861f9fea23eac1f9c0117767a2

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:

331cadcc6cf24831670eb5071149962a

I hope you can help me,

Greetings

Can't Select A Result With The Enter Button

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 :) ๐Ÿ‘ ๐Ÿ’ฏ ๐ŸŽฑ

Adding a custom WHERE

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'?

Issue in Ajax Live Search

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

1) Desktop v. Mobile

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

wordpress

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.

  1. the script works perfect with my own database with the downloaded directory structure not running in wordpress.
  2. trying to load the index.php anywhere else other than the set directory structure downloaded, i get the following error.

"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.

  • when placeing the "include_once('FILE DIRECTORY/index.php');" in your wordpress page or post, only the url and src locations need to be updated in index.php to exactly where on the server they are located AND editing the 2 js files to their proper locations.

Great Program, thank you for sharing!

Send Selected Values to another page

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.

Searching numbers bug

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.