autocomplete from mysql db

Home Forums Quform WordPress autocomplete from mysql db

This topic is: resolved
Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #35699
    Icemanmx
    Participant

    Hello
    I am trying to make that when you write 2 words it should start to read the database for autocomplete and fill out some fields, i attached an image for that.
    Now, do we have a manual of it or you think you can help me with some code and how to use it?

    Best Regards
    Icemanmx

    #35703
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #35706
    Icemanmx
    Participant

    Hello
    I found this, is this something maybe i can use?

    To add autocomplete functionality to a Quform input field using jQuery and MySQL, you can follow these steps:
    
        Set up the database:
            Create a MySQL database and table to store the data you want to use for autocompletion.
            For this example, let's assume you have a table named "products" with a column named "name" containing the product names.
    
        Create a custom WordPress plugin:
            Create a new directory in the wp-content/plugins directory of your WordPress installation. For example, you can name it "autocomplete-plugin".
            Inside the "autocomplete-plugin" directory, create a new PHP file, e.g., "autocomplete.php", and add the following code:


    <?php
    /*
    Plugin Name: Autocomplete Plugin
    */

    function enqueue_autocomplete_scripts() {
    // Enqueue necessary scripts for autocomplete
    wp_enqueue_script('jquery-ui-autocomplete');
    }
    add_action('wp_enqueue_scripts', 'enqueue_autocomplete_scripts');

    function autocomplete_search_results() {
    global $wpdb;

    $term = $_GET['term'];

    // Prepare the SQL query
    $query = "SELECT name FROM ".$wpdb->prefix."products WHERE name LIKE '%".$term."%'";
    $results = $wpdb->get_col($query);

    // Format the results as JSON
    echo json_encode($results);
    exit;
    }
    add_action('wp_ajax_autocomplete_search_results', 'autocomplete_search_results');
    add_action('wp_ajax_nopriv_autocomplete_search_results', 'autocomplete_search_results');

    Activate the plugin:
    
        Log in to your WordPress admin dashboard.
        Go to the "Plugins" section.
        Find your "Autocomplete Plugin" and click the "Activate" button.
    
    Modify the Quform form:
    
        Edit the Quform form you want to add autocomplete to.
        Find the input field you want to enable autocomplete for.
        In the "Advanced" section of the field settings, set the "Custom element class" to something unique, e.g., "autocomplete-field".
    
    Create a custom template file:
    
        In your WordPress theme's directory, create a new PHP file, e.g., "quform-autocomplete-template.php".
        Add the following code to the template file:


    <script>
    jQuery(document).ready(function($) {
    $(".autocomplete-field").autocomplete({
    source: "<?php echo admin_url('admin-ajax.php'); ?>?action=autocomplete_search_results",
    minLength: 1
    });
    });
    </script>

    Edit the Quform form shortcode:
    
        Locate the shortcode for your Quform form in the content area of your WordPress page or post.
        Add the include parameter to the shortcode, pointing to the custom template file:

    [quform id="YOUR_FORM_ID" include="path/to/quform-autocomplete-template.php"]

        Replace "YOUR_FORM_ID" with the actual ID of your Quform.
    
        Save the changes to the template file and the Quform shortcode.
    
    Now, when you view the page or post containing the Quform, the input field with the "autocomplete-field" class will have autocomplete functionality. As the user types in the field, an AJAX request will be sent to the server to retrieve matching results from the "products" table. The results will be displayed as suggestions in the autocomplete dropdown.

    Can you check if i can use this, i don´t want a dropdown i just want to search on client textfield and that when right client show up i just choose it then all the others fields will be populatet…

    Or do you have a develooper for me? who can make this plugin for me?

    Best Regards
    Icemanmx

    Attachments:
    You must be logged in to view attached files.
    #35708
    Icemanmx
    Participant

    Hello again,
    maybe this plugin will work, but i have problem to exact put together the quform id and Unique ID, i need help with that if you can, i can also give some money for the help… I will understand if this is total outside your area to work with.
    I will attache the files i have so far for the autocomplete…

    Best Regards
    Icemanmx

    Attachments:
    You must be logged in to view attached files.
    #35720
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #35722
    Icemanmx
    Participant

    Thanks alot… take your time, I am very grateful for your help.

    Regards
    Icemanmx

    #35763
    Icemanmx
    Participant

    Hello
    Just want to know if we have any progress on this one, is only this was is missing for my orden de trabajo to be complete?

    Best Regards
    Icemanmx

    #35764
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    Attachments:
    You must be logged in to view attached files.
    #35767
    Icemanmx
    Participant

    Hello
    I got some problems, i will attache the zip file with the wp-admin/error.log and also some screenshots what i want to show, i guess is not hard failure, just I need to understand them… I did all the setting on .js and .php file, i sending them in this zip file as well.
    One is this, maybe it is only this error:

    [20-Jul-2023 19:57:15 UTC] WordPress database error Table 'iceman_factura.wp_wp_ibodt_tbl_clientes' doesn't exist for query SELECT * FROM wp_wp_ibodt_tbl_clientes WHERE cli_nombre LIKE '%ha%' made by do_action('wp_ajax_quform_autocomplete'), WP_Hook->

    wp_wp_ibodt_tbl_clientes i only have this table wp_ibodt_tbl_clientes so maybe it does not read the data base…

    It puts a extra wp_ in the table name.

    Best Regards
    Icemanmx

    Attachments:
    You must be logged in to view attached files.
    #35770
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #35774
    Icemanmx
    Participant

    Hello
    That made the trick, function perfect now and the ib-odt is complete script.
    Thanks alot
    So, what paypal email you have so i can send you some coffee?

    Best Regards
    Icemanmx

    #35775
    Icemanmx
    Participant

    Hello
    One thing more, i forgot that i have two databases that should take the autocomplete, one is the vendedores, two fields with vendedores name and vendedores e-mail. When searching the vendedores name and select it should autocomplete the vendedores e-mail address.
    So, how can we do that when we have two tables to read from? Can we merge or make inner join or something for this? The two db tables wp_ibodt_tbl_clientes and wp_ibodt_tbl_vendedor.

    I will attache some images…

    Best Regards
    Icemanmx

    Attachments:
    You must be logged in to view attached files.
    #35777
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    Attachments:
    You must be logged in to view attached files.
    #35780
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #35787
    Icemanmx
    Participant

    Hello
    Thanks for your outstanding support and help, i donated $50 to your ThemeCatcher Ltd.
    Transaction ID: 17C585593R705802P

    Best Regards
    Icemanmx

Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy