/** * Create and getting the singelton instance * * @return FormAPIFactory instance of factory class */ public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; }
/** * Process uploaded form data * * Sample code */ /** * User defined callback function if field validation fails. * * @param Field $f field object with invalid content */ function request_error_callback($f) { echo "Invalid value: " . $f->getName(); } try { include_once "FormAPI/import.php"; include_once "config.php"; // error_reporting(E_ALL); // Display results on client side $model = new EchoModel(); // Create control object $formapi = FormAPIFactory::getInstance()->create("sample.xml", "upform.php", $model); //Handle bad request with an anonymous function $formapi->setInvalidRequestHandler(request_error_callback); // Process request $w = $formapi->request($_REQUEST); // Print result echo $w; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }
<?php /** * User defined callback function if field validation fails. * * @param Field $f field object with invalid content */ function request_error_callback($f) { echo "Invalid value: " . $f->getName(); } include_once "FormAPI/import.php"; $model = new EchoModel(); $formapi = FormAPIFactory::getInstance()->create("sample.xml", $_SERVER['PHP_SELF'], $model); // TODO improve condition more specific to form if (is_array($_REQUEST) && count($_REQUEST) > 2) { $formapi->setInvalidRequestHandler("request_error_callback"); // response for submit $w = $formapi->request($_REQUEST); echo $w; } else { // generate form $w = $formapi->generate("en", 0); echo $w; }