PHP code example of germania-kg / formvalidator

1. Go to this page and download the library: Download germania-kg/formvalidator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

germania-kg / formvalidator example snippets



use Germania\FormValidator\FormValidator;
use Germania\FormValidator\InputContainer;

// Setup
$r_login_name" =>   FILTER_SANITIZE_STRING
];

$optional = [
	"family_name"     =>   FILTER_SANITIZE_STRING,
	"first_name"      =>   FILTER_SANITIZE_STRING
];

$formtest = new FormValidator( $valid?
echo $formtest->isSubmitted();

// All 

$formtest = new FormValidator( $onal_info', FILTER_SANITIZE_STRING);
$formtest->addOptional('additional_info', FILTER_SANITIZE_STRING);

$formtest = new FormValidator( $r_email');
$formtest->removeOptional('family_name');


// Invocation returns InputContainer instance
$filtered_input = $formtest( $_POST );

// ArrayAccess: 
// If field not set, return values are null.
echo $filtered_input['foo'];
echo $filtered_input->offsetGet('foo');


// Invocation returns InputContainer instance
$filtered_input = $formtest( $_POST );

$input_array = $filtered_input->getArrayCopy();


use Germania\FormValidator\NotFoundException;
use Psr\Container\NotFoundExceptionInterface;

// Invocation returns InputContainer instance
$filtered_input = $formtest( $_POST );

try {
	echo $filtered_input->has('foo');
	echo $filtered_input->get('foo');
}
catch (NotFoundException $e) {
	// not found
}
catch (NotFoundExceptionInterface $e) {
	// not found
}

// Setup the factory
$factory = function( $filtered_input ) {
    return new \ArrayObject( $filtered_input );
};

// Pass to the ctor
$formtest = new FormValidator( $

// Setup as usual:
$formtest = new FormValidator( $he above returns the usual InputContainer,
// this will return an ArrayObject:
$filtered_input = $formtest( $_POST, function( $filtered_input ) {
    return new \ArrayObject( $filtered_input );
});