I ended up using a regex to get the username and then queried the
database for the username in the controller. From this I got the id.
Probably not the best way, but it seemed like the easiest and the one
that would work on the widest range of platforms.
Mike.
On 3/17/07, Jeremy Pointer <[EMAIL PROTECTED]> wrote:
> 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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---