Registration form with all features?

Hi all,
In my site, i developed registration form, it is working fine…
But i want to add some features to it…
like;

  1. Add error messages beside the each form field only…
  2. If the username and email address are already registered, then popup messages will come.
    3.Use captcha in the form to validate.
    4.All error messages will come in the same page only…

Give me some live example and suggestions to do it…
Thanking you all…

With respect I suggest you google for [google]php form validation[/google] initially.

Have a go at following some of the tutorials that throws up, then come back when you have had a go and post some code describing each single problem as you find it.

For client side validation on the page itself, the jQuery validation plugin is very popular. See the Remember the Milk example.

For server-side validation on the same page, include your validation script on the same page & have the form submit to itself, e.g.,

<form action="<?php echo $_SERVER['REQUEST_URI']; ?>"method="post">

Here’s a simplified example:

<html lang="en">
<body>
<form action="<?php echo $_SERVER['REQUEST_URI']; ?>"method="post">
<?php
// If the form is submitted
if((isset($_POST['verify']))||(isset($_POST['submit']))) {
	//Create individual variables from $_POST
	
	extract($_POST);

	$error="<p>The following errors occured while processing your form input.</p><ul>";

	if($firstName==""){
		$errors = 1;
		$error.="<li><strong>First name</strong> required</li>";
	}

	if ($firstName!=""){
	// use regular expression to contstrain input
		if(preg_match('/[^\\w\\.\\s]+/i',$firstName)){
			$errors=1;
			$error.="<li>Enter only numerals, letters, or periods in your <strong>first name</strong> please</li>";
		}
	}

	if(isset($errors)) {
		echo "<div class='error'>".$error."</ul><p>Please go back &amp; try again.</p></div>";
	}

	else {
		$message="------------------------------------------------------------
Name			|	".htmlspecialchars($firstName, ENT_NOQUOTES, 'UTF-8')."
------------------------------------------------------------";
	}
		
		if(isset($_POST['verify'])) {
			echo "<fieldset><legend>Verify &amp; Send</legend><p>Please check your form submission. When you are satisfied that the information is correct, click the &ldquo;Send Form&rdquo; button (located <a href='#submit'>here</a>) <em>only once.</em></p><p><pre>".$message."</pre></p><label for='submit'>If you are satisfied that your information is correct, click &ldquo;Send Form&rdquo; button only once. Otherwise, scroll down to make corrections and click &ldquo;Verify&rdquo;.</label><div ><button type=\\"submit\\" class=\\"submit\\" name=\\"submit\\" id=\\"submit\\">Send Form</button></div></fieldset>";
		} 
		
	//php to mail message here
}	
?>

<fieldset>
<legend>Who Are You?</legend>
<label for="firstName" title="First Name" class="required">First Name</label>
<input type="text" name="firstName" id="firstName" value="<?php if(isset($_POST['firstName'])){echo htmlentities($_POST['firstName']) ?><?php } ?>" maxlength="13" />
<button type="submit" class="submit" name="verify" id="verify">Submit</button>
<button type="submit" name="reset" id="reset">Reset</button>
</fieldset>
</form>
</body>
</html>