Home › Forums › Quform WordPress › autocomplete from mysql db
- This topic has 15 replies, 2 voices, and was last updated 1 year, 5 months ago by Ally.
- AuthorPosts
- July 3, 2023 at 9:16 pm #35699IcemanmxParticipant
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
IcemanmxJuly 4, 2023 at 10:40 am #35703AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 4, 2023 at 5:39 pm #35706IcemanmxParticipantHello
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
IcemanmxAttachments:
You must be logged in to view attached files.July 4, 2023 at 11:54 pm #35708IcemanmxParticipantHello 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
IcemanmxAttachments:
You must be logged in to view attached files.July 6, 2023 at 11:39 am #35720AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 8, 2023 at 4:05 am #35722IcemanmxParticipantThanks alot… take your time, I am very grateful for your help.
Regards
IcemanmxJuly 19, 2023 at 6:37 pm #35763IcemanmxParticipantHello
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
IcemanmxJuly 20, 2023 at 10:25 am #35764AllySupport StaffYou 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.July 20, 2023 at 9:28 pm #35767IcemanmxParticipantHello
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
IcemanmxAttachments:
You must be logged in to view attached files.July 21, 2023 at 9:49 am #35770AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 21, 2023 at 4:32 pm #35774IcemanmxParticipantHello
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
IcemanmxJuly 23, 2023 at 9:29 pm #35775IcemanmxParticipantHello
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
IcemanmxAttachments:
You must be logged in to view attached files.July 24, 2023 at 9:39 am #35777AllySupport StaffYou 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.July 24, 2023 at 9:41 am #35780AllySupport StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
July 24, 2023 at 5:05 pm #35787IcemanmxParticipantHello
Thanks for your outstanding support and help, i donated $50 to your ThemeCatcher Ltd.
Transaction ID: 17C585593R705802PBest Regards
Icemanmx - AuthorPosts
- You must be logged in to reply to this topic.