Isn't it a small world.... This is from something I did, No change in the controller but I've modified the below views, the key is to set the user id as the id of the <li> tag in autocomplet, and then have a 'user_id' input and a touch of javascritpt in the send view to update the id field, then set the 'afterUpdateElement' option in $ajax->autocomplete()
autocomplete.thtml: <ul> <?php foreach($users as $user): ?> <li id="<?php echo $user['User']['id']; ?>"><?php echo $user['User']['username'].' ('.$user['User']['fname'].' '.$user['User']['lname'].')'; ?></li> <?php endforeach; ?> </ul> send.thtml: <form action="<?php echo $html->url('/messages/send'); ?>" method="post"> <?php echo $html->input('Message/user_id'); ?> <script type= 'text/javascript'> function getSelectionId(text, li) { alert(li.id); document.getElementById('MessageUserId').value=li.id; } </script> <?php echo $ajax->autocomplete('Message/user','/contacts/autocomplete', array('size' => 40, 'afterUpdateElement'=>'getSelectionId' ) ); ?> <?php echo $html->textarea('Message/message', array('cols' => '60', 'rows' => '10')); ?> <div class="submit"> <?php echo $html->submit('Send');?> </div> </form> HTH JermWorm Mike Griffin wrote: > On 3/16/07, fredBH <[EMAIL PROTECTED]> wrote: > >> can you post the code ? >> > > Sure, here is the sutocomplete.thtml file. It returns the username > and then the full name in brackets > <ul> > <?php foreach($users as $user): ?> > <li><?php echo $user['User']['username'].' ('.$user['User']['fname'].' > '.$user['User']['lname'].')'; ?></li> > <?php endforeach; ?> > </ul> > > The form is in send.thtml > > <form action="<?php echo $html->url('/messages/send'); ?>" method="post"> > <?php echo $ajax->autocomplete('Message/user', > '/Messages/autocomplete', array('size' => 40)); ?> > > <?php echo $html->textarea('Message/message', array('cols' => '60', > 'rows' => '10')); ?> > <div class="submit"> > <?php echo $html->submit('Send');?> > </div> > </form> > > And the autocomplete function from the messages controller: > function autocomplete() { > $this->set('users', $this->User->findAll(array('User.username' => > 'LIKE '.$this->data['Message']['user'].'%'), array('User.username', > 'User.fname', 'User.lname', 'User.id'), 'username DESC',null, null, > 0)); > $this->layout = "ajax"; > } > > So the function returns the User.id but I cant see how to pass that to > the view and back again. > > Mike. > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
begin:vcard fn:Jeremy Pointer n:Pointer;Jeremy adr:;;Box 499;Krugersdorp;Gauteng;1740;South Africa email;internet:[EMAIL PROTECTED] tel;work:+27 11 665-2445 tel;fax:+27 86 5013109 tel;cell:+27 82 3724769 x-mozilla-html:TRUE version:2.1 end:vcard