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

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">


<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" />

<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 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" />

<br /><br />

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

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
				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>';
    		$processor->display(); //print the form
		$processor->display(); //print the form
catch(Exception $e) { //an error occured
	echo $e->getMessage(); //print the error message
Return current item: PHP Form Processor