Maybe this helps?
http://stackoverflow.com/questions/9750326/intercept-cake2-postlink-form-posts-with-jquery


Am Samstag, 7. Februar 2015 17:34:38 UTC+1 schrieb MarkB:
>
> Hi,
>
> My first Cake project (and first major non-intranet web project!) is a 
> fairly complex event management system for a month-long city-wide science 
> festival my employer runs, involving about 120 events.
>
> I have added the ability to add (and remove) events to a wishlist from a 
> *postLink*, which works well on the event view page, but is annoying for 
> users when clicking the 'Add to wishlist' link in the events listings page, 
> as the page refreshes and they may have to scroll down to continue browsing 
> where they left off.
>
> I've been messing about with PHP for years, but have little Javascript 
> experience and nothing AJAX-based. Time is getting tight, so I'm wondering 
> if there is anyone who can help me achieve this? Thanks!
>
> This is the code I use in my view:
>
>  if ($wishlisted == NULL){
>  echo $this->Form->postLink('Add to wishlist', array('action' => 'wishadd'
> , $event['Event']['id']));
>  } else {
>  echo "On your wishlist " . $this->Form->postLink('Remove', array('action' 
> => 'wishlistremove', $wishlisted));
>  }
>
>
>
>
> This is my Controller code:
>
> public function wishadd($id) {
>  if ($this->request->is('get')) {
>         throw new MethodNotAllowedException();
>     }
>  $user_id = $this->Auth->user('id');
>  if ($user_id == NULL) {
> $this->Session->setFlash('You must be logged in to add an event to a 
> wishlist!');
> return $this->redirect(array('action' => 'view',$id));
> }
>  $currentYear = $this->getSettings('year');
> $event = $this->Event->findById($id); 
>  $conditions = array('Wishlist.year' => $currentYear,'Wishlist.event_id' 
> => $id,'Wishlist.user_id' => $this->Auth->user('id'));
> $wishlisted = $this->Event->Wishlist->find('count',array('conditions' => 
> $conditions));
>  if ($wishlisted > 0) {
> $this->Session->setFlash('This event is already on your wishlist.');
> return $this->redirect($this->referer());
> }
>  if ($this->request->is('post')) {
>  $this->Event->Wishlist->create();
> $wishlist_id = $this->Event->Wishlist->getInsertID();
> $this->Event->Wishlist->saveField('year', $currentYear);
> $this->Event->Wishlist->saveField('event_id', $id);
> $this->Event->Wishlist->saveField('proposal_id', 
> $event['Event']['proposal_id']);
> $this->Event->Wishlist->saveField('user_id', $user_id);
>  $this->Session->setFlash('This event has been added to your wishlist.');
> return $this->redirect($this->referer());
> } else {
> $this->Session->setFlash('Unable to add to your wishlist. Please try 
> again.');
> return $this->redirect($this->referer());
>  }
> }
>
>
>
>
>
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to