Location: PHPKode > scripts > PHP Form Processor > php-form-processor/examples/password.php
<?php
session_start(); //start the session
require_once('../class.formprocessor.php'); //include the form processor
?>
<html>
<head>
<title>Password change</title>
</head>
<body>
<?php

function checkPwd($val) {
	//put a database query here that checks the user's password ($val) in the database. If it is correct, return true. Otherwise, return false
	return true;
}

function myform() {
$form = <<<EOD
<form id="password" action="password.php" method="post">

<errorlist>
<ul>
	<erroritem>
		<li><error/></li>
	</erroritem>
</ul>
</errorlist>

<label for="pwdo">Current password:</label>
<element id="pwdo">
<input type="password" />
<compulsory message="You must enter your old password!" />
<callback function="checkPwd" message="The password you entered is incorrect!" />
<error> <strong class="error">!</strong></error>
</element>

<br /><br />

<label for="pwd1">New password:</label>
<element id="pwd1">
<input type="password" />
<compulsory message="You must enter your new password!" />
<minLength length="4" message="Your new password is too short! It must be greater than 3 characters." />
<error> <strong class="error">!</strong></error>
</element>

<br /><br />

<label for="pwd2">Confirm new password:</label>
<element id="pwd2">
<input type="password" />
<compulsory message="You must confirm your new password!" />
<match element="pwd1" message="Your new passwords don't match!" />
<error> <strong class="error">!</strong></error>
</element>

<br /><br />

<element id="update1">
<input type="submit" value="Change password" class="submito" />
</element>


</form>
EOD;
return $form;
}

try {
	$processor =& new FormProcessor(myform()); //create a new instance of the form processor
	if(isset($_POST["update1"])) { //if the form has been submitted
		if ($processor->validate()) { //if the form validated
			echo '<h1>Success!</h1>';
			print_r($_POST); //print the form variables
		}
		else
    		$processor->display(); //print the form
	}
	else
		$processor->display(); //print the form
}
catch(Exception $e) { //an error occured
	echo $e->getMessage(); //print the error message
}
?>
</body>
</html>
Return current item: PHP Form Processor