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

function functionname1($val) {
	//Take the user input ($val) and perform some checks on it. Return true if it ok or false if it isn't
	return true;
}

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

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

<label for="radio">Radio:</label>
<element id="radio">
	<input type="radio" value="yay" name="groupname" />
	<checked value="true" />
	<error><strong class="error">!</strong></error>
	<callback function="functionname1" message="callback 1 failed for radio" />
</element>

<label for="radio2">Radio2:</label>
<element id="radio2">
	<input type="radio" value="yay2" name="groupname" />
	<checked value="false" />
	<error><strong class="error">!</strong></error>
</element>

<element id="myBox">
 <input type="text" />
 <error><strong class="error">!</strong></error>
 <compulsory message="myBox must be filled in" />
 <validate test="alpha" message="myBox must only contain letters" />
 <text transform="ucwords" />
</element>

<br /><br />

<element id="submitForm">
	<input type="submit" value="Go!" />
</element>

</form>
EOD;
return $form;
}


try {
	$config = array();
	$config['csrf'] = false; //turn off cross site request forgery protection. This allows any form on any website to post to your form, as well as resubmitting the same form. Set to true by default
	$config['display'] = true; //if this is set to true the form will be printed to the browser using echo ($processor->display();). If it is set to false it will be returned ($var = $processor->display();). Set to true by default.
	$processor =& new FormProcessor(myform(),$config); //create a new instance of the form processor, passing the config array as a parameter
	if(isset($_POST["submitForm"])) { //if the form has been submitted
		if ($processor->validate()) { //if the form validated
			echo '<h1>Success!</h1>';
			print_r($_POST); //print the form variables
			if($config['csrf']==false)
				echo '<p>CSRF protection is turned off. Try hitting F5 in your browser to resubmit the form. When CSRF protection is turned on the user won\'t be able to resubmit the form, and will be presented with an error message.</p>';
		}
		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