Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* I'm not able to get it working after editing the code. What I did was changing the id y name of all the fields and php code.
- I.E. nombre replaced city, so in each appearence of city, I changed it.
- Is this incorrect? Am I missing something?
- This is my HTML: */
- <script type="text/javascript">
- jQuery(document).ready(function(){
- var ac_config = {
- source: "datos.php",
- select: function(event, ui){
- jQuery("#nrocliente").val(ui.item.nrocliente);
- jQuery("#nombre").val(ui.item.nombre);
- jQuery("#apellido").val(ui.item.apellido);
- jQuery("#mensaje").val(ui.item.mensaje);
- },
- minLength:1
- };
- jQuery("#nombre").autocomplete(ac_config);
- });
- </script>
- <form method="post" action="/">
- <input type="hidden" name="page_id" id="page_id" value="12" />
- <label for="nombre">Nombre:</label> <input type="text" name="nombre" id="nombre" value="" /><br />
- <label for="apellido">Apellido:</label> <input type="text" name="apellido" id="apellido" value="" /><br />
- <label for="mensaje">Mensaje:</label> <input type="text" name="mensaje" id="mensaje" value="" /><br />
- <input type="hidden" name="nrocliente" id="nrocliente" value="" />
- <input type="submit" value="Enviar" /><br />
- </form>
- // And this is my datos.php file:
- <?php
- // Wordpress database call through $wpdb
- $clientes = $wpdb->get_results('SELECT id AS nrocliente, nombre, apellido, mensaje FROM clientes');
- // Turns the array of objects into an array of arrays, exactly like the example
- $array = array();
- foreach($clientes as $cliente){
- $arrcli = (array) $cliente;
- $array[] = $arrcli;
- }
- //print_r($array);
- // Cleaning up the term
- $term = trim(strip_tags($_GET['term']));
- // Rudimentary search
- $matches = array();
- foreach($array as $data){
- if(stripos($data['nombre'], $term) !== false){
- // Add the necessary "value" and "label" fields and append to result set
- $data['value'] = $data['nombre'];
- $data['label'] = "{$data['nombre']}, {$data['apellido']} {$data['mensaje']}";
- $matches[] = $data;
- }
- }
- // Truncate, encode and return the results
- $matches = array_slice($matches, 0, 5);
- print json_encode($matches);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement