Archive

Archive for the ‘AJAX’ Category

Ajax Form Post with Cakephp

November 14, 2011 1 comment

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();”>

</form>

Javascript Code:

function save()
{

var base=$(“#ajaxPostForm”);

var params=base.serialize();

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

}
});

}

Cakephp Code:
<?php

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:

How to Create CAPTCHA Protection using PHP and AJAX

September 16, 2009 Leave a comment

CAPTCHA is a simple test to determine if a user is a computer or a human. It is used to prevent spam abuse on the websites. So if you use CAPTCHA on your web site forms, this can help in stopping some bots and making life harder for other bots in accessing or using your forms.

In brief the CAPTCHA protection works by generating a random string, writing it to an image, then storing the string inside of a session or by some other method. This is then checked when the form is submitted.

The goal of this tutorial is to demonstrate how to make your own simple CAPTCHA protection using PHP and AJAX technologies.

This tutorial is very simple, but if you are unfamiliar with PHP and AJAX this is a great place to start. The tutorial consists of a HTML page for presenting a simple form that will send the data, a JavaScript file for handling the Ajax functionality, and a simple PHP page that makes the actual comparison of the what is in the text box compared to what phrase was stored in the image.

    Categories: AJAX