I'm still stuck on this... Any help would be appreciated. Here's the
form code in my view:
<?=$ajax->form(array('action' => '/member/address_books'),
'post',
array('update' => 'addressBookContent')) ?>
<div class="optional">
<?=$form->labelTag('User/username',
'Username: ') ?>
<?=$ajax->autocomplete('User/username',
'/member/address_books/auto') ?>
<?=$html->submit('Add Contact') ?>
<?=''//$ajax->submit('Add Contact',
array('url' =>
'/member/address_books/add', 'update' => 'addressBookContent',
'class'=>'submit-form')); ?>
</div>
</form>
and here's the controller code:
<?php
/** \brief Address Books Controller
**/
class AddressBooksController extends AppController
{
var $name = 'AddressBooks';
var $uses = array('AddressBook', 'User');
// var $scaffold;
var $helpers = array('html', 'ajax', 'text', 'time');
var $components = array('Autocomplete');
function __construct() {
parent::__construct();
}
/** \brief index the model for return to a view
\sa
**/
function index() // this will basically be view and add
{
if (empty($this->data)) {
$data =
$this->AddressBook->findByUserId($this->Session->read('User.id'));
if (empty($data)) {
$this->AddressBook->save(array('AddressBook' =>
array('user_id' =>
$this->Session->read('User.id'))));
$data =
$this->AddressBook->findByUserId($this->Session->read('User.id'));
$users = array();
}
$this->set('data', $data);
$users = array();
foreach ($data['User'] as $key => $user) if
(is_numeric($key))
$users[$user['username']] = $user['username'];
$this->set('users', $users);
$this->render();
} else {
$this->cleanUpFields();
$addressBook =
$this->AddressBook->findByUserId($this->Session->read('User.id'));
if (!empty($this->data['User']['username'])) $user =
$this->User->findByUsername($this->data['User']['username']);
if (!empty($this->data['User']['username']) &&
$this->AddressBook->addAssoc($addressBook['AddressBook']['id'], 'User',
$user['User']['id'])) {
$data =
$this->AddressBook->findByUserId($this->Session->read('User.id'));
$this->set('data', $data);
$users = array();
foreach ($data['User'] as $key => $user) if
(is_numeric($key))
$users[$user['username']] = $user['username'];
$this->set('users', $users);
$this->Session->setFlash(ucwords($this->data['User']['username']) .
' Is Now In Your Address Book.');
$this->render();
} else {
$this->Session->setFlash('Contact Username Not
Found.');
$data =
$this->AddressBook->findByUserId($this->Session->read('User.id'));
$this->set('data',$data);
$users = array();
foreach ($data['User'] as $key => $user) if
(is_numeric($key))
$users[$user['username']] = $user['username'];
$this->set('users', $users);
}
}
} // END function index
} // END class AddressBooksController
?>
I've tried several different things and can't seem to get autocomplete
working inside the ajax form.
thanks again,
chowsapal
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---