i have this form that is php and it has some required fields.
that get checked with php .
but i know that javascript can be disabled so i want to keep the php code because it does all the error checking but i want to add javascript to look nice and i want to make it so the form doesnt have to submit to a new page or even reload!
right now i have a script that i put together. that has these things on it that are all
on the same pae im making it reload the page to submit. its an email verifying form meaning it sends and email witht he verification code to actually be a member.
here is the code: how can i make it so it becomes a form that never reloads the page?
thats what i want.
<?php session_start(); ?>
<html>
<?php
if ($_POST['form_submitted'] == '1') {
## Form submitted, user registering!
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// handle the error accordingly with your other error checking
// or you can do something really basic like this
die('The code you entered was incorrect. go back and try again.');}
mysql_connect("localhost", db, xxxx) or die(mysql_error());
mysql_select_db("xxxxxx") or die(mysql_error());
##User is registering, insert data until we can activate it
$activationKey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();
$username = mysql_real_escape_string($_POST[username]);
$password = mysql_real_escape_string($_POST[password]);
$email = mysql_real_escape_string($_POST[email]);
$sex = mysql_real_escape_string($_POST[sex]);
$age = mysql_real_escape_string($_POST[age]);
$location = mysql_real_escape_string($_POST[location]);
$ethnicity = mysql_real_escape_string($_POST[ethnicity]);
$marital = mysql_real_escape_string($_POST[marital]);
$sexuality = mysql_real_escape_string($_POST[sexuality]);
$haircolor = mysql_real_escape_string($_POST[haircolor]);
$name = mysql_real_escape_string($_POST[name]);
$eye = mysql_real_escape_string($_POST[eye]);
$hairtype = mysql_real_escape_string($_POST[hairtype]);
$weight = mysql_real_escape_string($_POST[weight]);
$height = mysql_real_escape_string($_POST[height]);
$ip = mysql_real_escape_string($_POST[ip]);
$date = mysql_real_escape_string($_POST[date]);
if($username == "") {
die ("You must fill username. ");
}
if($password == "") {
die ("You must fill password. ");
}
if($email == "") {
die ("You must fill email. ");
}
if($sex == "") {
die ("You must fill sex. ");
}
if($age == "") {
die ("You must fill age. ");
}
if($location == "") {
die ("You must fill location. ");
}
$sql="INSERT INTO users (username, password, email, sex, age, location, ethnicity, marital, sexuality, haircolor, name, eye, hairtype, weight, height, ip, date, activationkey, status) VALUES ('$username', '$password', '$email', '$sex', '$age', '$location', '$ethnicity', '$marital', '$sexuality', '$haircolor', '$name', '$eye', '$hairtype', '$weight', '$height', '$ip', '$date', '$activationKey', 'verify')";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
echo "An email has been sent to $_POST[email] with an activation key. Please check your mail to complete registration.";
##Send activation Email
$to = $_POST[email];
$subject = " socialemo.com Registration";
$message = "Welcome to our website!\r\rYou, or someone using your email address, has almost completed registration at socialemo.com. You can complete registration by clicking the following link:\rhttp://www.socialemo.com/register.php?$activationKey\r\rIf this is an error, ignore this email and your email will be removed from our database.\r\rRegards, socialemo.com";
$headers = 'From: noreply@ socialemo.com' . "\r\n" .
'Reply-To: noreply@ socialemo.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
else {
##User isn't registering, check verify code and change activation code to null, status to activated on success
mysql_connect("localhost", xxxxx, xxxxxxx) or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
$queryString = $_SERVER['QUERY_STRING'];
$query = "SELECT * FROM users";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
if ($queryString == $row["activationkey"]){
echo "Congrats! " . $row["username"] . " is a member of socialemo.com.";
$sql="UPDATE users SET activationkey = '', status='activated' WHERE (id = $row[id])";
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
}
}
}
?>
<head>
<title>Social Emo - Register</title>
<link href="style/style.css" rel="stylesheet" type="text/css" /><link rel="shortcut icon" href="http://www.socialemo.com/favicon/favicon.ico">
</head>
<body> <center>
<span style="text-transform:none;font-size:32px;line-height:33px;letter-spacing:-2px;font-weight:bold;font-family:arial;word-spacing:2px;font-variant:small-caps">Requ</span><span style="font-size:32px;line-height:33px;letter-spacing:-2px;font-weight:bold;font-family:arial;word-spacing:2px;font-variant:none;text-transform:lowercase">i</span><span style="text-transform:none;font-size:32px;line-height:33px;letter-spacing:-2px;font-weight:bold;font-family:arial;word-spacing:2px;font-variant:small-caps">red Informat</span><span style="font-size:32px;line-height:33px;letter-spacing:-2px;font-weight:bold;font-family:arial;word-spacing:2px;font-variant:none;text-transform:lowercase">i</span><span style="text-transform:none;font-size:32px;line-height:33px;letter-spacing:-2px;font-weight:bold;font-family:arial;word-spacing:2px;font-variant:small-caps">on</span><br>
<form action="register.php" method="post" name="register">
<table width="500px" cellspacing="0">
<tr><td>Username: </td><td><input type="text" name="username" /></td></tr>
<tr><td>Password: </td><td><input type="password" name="password" /></td></tr>
<tr><td>Email: </td><td><input type="text" name="email" /></td></tr>
<tr><td>Sex: </td><td><input type="radio" name="sex" value="male" />m<input type="radio" name="sex" value="female" />f<input type="radio" name="sex" value="other" />other</td></tr>
<tr><td>Age: </td><td><select name="age">
<option value=""></option>
<option value="youngest">0-12</option>
<option value="young">13-17</option>
<option value="adult">18-30</option>
<option value="older">31-50</option>
<option value="oldest">51+</option>
</select></td></tr>
<tr><td>Location: </td><td><input type="text" name="location" /></td></tr>
</table>
<br>
<span style="text-transform:none;font-size:32px;line-height:33px;letter-spacing:-2px;font-weight:bold;font-family:arial;word-spacing:2px;font-variant:small-caps">Other Prof</span><span style="font-size:32px;line-height:33px;letter-spacing:-2px;font-weight:bold;font-family:arial;word-spacing:2px;font-variant:none;text-transform:lowercase">i</span><span style="text-transform:none;font-size:32px;line-height:33px;letter-spacing:-2px;font-weight:bold;font-family:arial;word-spacing:2px;font-variant:small-caps">le Informat</span><span style="font-size:32px;line-height:33px;letter-spacing:-2px;font-weight:bold;font-family:arial;word-spacing:2px;font-variant:none;text-transform:lowercase">i</span><span style="text-transform:none;font-size:32px;line-height:33px;letter-spacing:-2px;font-weight:bold;font-family:arial;word-spacing:2px;font-variant:small-caps">on</span><br>
<table width="500px" cellspacing="0">
<tr><td>Ethnicity: </td><td><input type="text" name="ethnicity" /></td></tr>
<tr><td>Marital Status: </td><td><input type="text" name="marital" /></td></tr>
<tr><td>Sexuality: </td><td><select name="sexuality">
<option value="str8">str8</option>
<option value="gay">gay</option>
<option value="bi">bi</option>
<option value="not interested">not interested</option>
<option value="other">other</option>
</select></td></tr>
<tr><td>Hair Color: </td><td><input type="text" name="haircolor" /></td></tr>
<tr><td>1st Name: </td><td><input type="text" name="name" /></td></tr>
<tr><td>Eye Color: </td><td><input type="text" name="eye" /></td></tr>
<tr><td>Hair Type: </td><td><input type="text" name="hairtype" /></td></tr>
<tr><td>Weight: </td><td><input type="text" name="weight" /></td></tr>
<tr><td>Height: </td><td><input type="text" name="height" /></td></tr>
<tr><td></td><td><input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR'] ?>" />
<input type="hidden" name="date" value="<?php
echo date("n/d/y");
$time = date("|h:i:s",time());
echo $time ?>" /><input type="hidden" name="form_submitted" value="1"/></td></tr>
<tr><td><img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" /></td><td><input type="text" name="captcha_code" size="10" maxlength="5" /> </td></tr>
<tr><td><a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">Reload Image</a></td></tr>
<table width="500px" cellspacing="0"><tr><td><center><input type="submit" value="submit" /></center></td></tr></table>
</form>
</table>
</center>
</body>
</html>