I want to use ajax to make my sites a bit sexier, but I'm stuggling to grasp how I'm going to implement it.
For example, here's a sample script for a sign-up form:
Code: Select all
<?php
session_start();
if(isset($_POST['signup']))
{
include('classes/class.signup.php');
$signUp = new SignUp();
if($signUp->signThemUp())
{
echo '<h3>Success!</h3><p>You have been successfully signed up.</p>';
}
else
{
$signUp->displayErrors();
}
}
$token = $_SESSION['token'] = md5(uniqid(mt_rand(),true));
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<p><label>First Name: </label><input type="text" name="firstname" /></p>
<p><label>Last Name: </label><input type="text" name="lastname" /></p>
<p><label>Email: </label><input type="text" name="email" /></p>
<p><label>Password: </label><input type="password" name="password" /></p>
<p><label>Retype Password: </label><input type="password" name="repassword" /></p>
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<p><input type="submit" name="signup" value="Sign Up" /></p>
</form>Now, my question is, how do I ajax-ify it? I'm not asking for a tutorial on ajax, I just want to know the best way of implementing it when using objects as above.
Thanks for your time!