Home > AJAX > Ajax Form Post with Cakephp

Ajax Form Post with Cakephp

Html Form

<form id=’ajaxPostForm’>

User Name :<input type=’text’ name=’user_name’>

Email : <input type=’text’ name=’user_email’>

Comments : <input type=’text’ name=’comments’>

<input value=”Save” type=”button” onclick=”save();”>


Javascript Code:

function save()

var base=$(“#ajaxPostForm”);

var params=base.serialize();

type: “GET”,
url: ‘<?php echo FULL_BASE_URL.$this->webroot.’users/data_save’; ?>’,
data: params,
success: function(msg){



Cakephp Code:

class UsersController extends AppController

var $name = ‘Users’;

function data_save()
$userName = $this->params[‘url’][‘user_name’];
$userEmail = $this->params[‘url’][‘user_email’];
$userComments = $this->params[‘url’][‘comments’];

$this->data[‘User’][‘user_name’] = $userName;

$this->data[‘User’][‘user_email’] = $userEmail;

$this->data[‘User’][‘comments’] = $userComments;

$this->User->save($this->data, false);




Categories: AJAX Tags:
  1. Adam Smith
    November 14, 2011 at 7:25 am

    Great Post

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: