HTMLPurifier_Config::loadArrayFromForm PHP Method

loadArrayFromForm() public static method

Loads configuration values from $_GET/$_POST that were posted via ConfigForm
public static loadArrayFromForm ( array $array, string | boolean $index = false, array | boolean $allowed = true, boolean $mq_fix = true, HTMLPurifier_ConfigSchema $schema = null ) : mixed
$array array $_GET or $_POST array to import
$index string | boolean Index/name that the config variables are in
$allowed array | boolean List of allowed namespaces/directives
$mq_fix boolean Boolean whether or not to enable magic quotes fix
$schema HTMLPurifier_ConfigSchema Schema to use, if not global copy
return mixed
    public static function loadArrayFromForm($array, $index = false, $allowed = true, $mq_fix = true, $schema = null)
    {
        $ret = HTMLPurifier_Config::prepareArrayFromForm($array, $index, $allowed, $mq_fix, $schema);
        $config = HTMLPurifier_Config::create($ret, $schema);
        return $config;
    }

Usage Example

Example #1
0
 public function test_loadArrayFromForm()
 {
     $this->schema->add('Pancake.Mix', 'buttermilk', 'string', false);
     $this->schema->add('Pancake.Served', true, 'bool', false);
     $this->schema->add('Toppings.Syrup', true, 'bool', false);
     $this->schema->add('Toppings.Flavor', 'maple', 'string', false);
     $this->schema->add('Toppings.Strawberries', 3, 'int', false);
     $this->schema->add('Toppings.Calories', 2000, 'int', true);
     $this->schema->add('Toppings.DefinitionID', null, 'string', true);
     $this->schema->add('Toppings.DefinitionRev', 1, 'int', false);
     $this->schema->add('Toppings.Protected', 1, 'int', false);
     $get = array('breakfast' => array('Pancake.Mix' => 'nasty', 'Pancake.Served' => '0', 'Toppings.Syrup' => '0', 'Toppings.Flavor' => "juice", 'Toppings.Strawberries' => '999', 'Toppings.Calories' => '', 'Null_Toppings.Calories' => '1', 'Toppings.DefinitionID' => '<argh>', 'Toppings.DefinitionRev' => '65', 'Toppings.Protected' => '4'));
     $config_expect = HTMLPurifier_Config::create(array('Pancake.Served' => false, 'Toppings.Syrup' => false, 'Toppings.Flavor' => "juice", 'Toppings.Strawberries' => 999, 'Toppings.Calories' => null), $this->schema);
     $config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', array('Pancake.Served', 'Toppings', '-Toppings.Protected'), false, $this->schema);
     $this->assertEqual($config_expect, $config_result);
     /*
     MAGIC QUOTES NOT TESTED!!!
     
     $get = array(
         'breakfast' => array(
             'Pancake.Mix' => 'n\\asty'
         )
     );
     $config_expect = HTMLPurifier_Config::create(array(
         'Pancake.Mix' => 'n\\asty'
     ));
     $config_result = HTMLPurifier_Config::loadArrayFromForm($get, 'breakfast', true, false);
     $this->assertEqual($config_expect, $config_result);
     */
 }
All Usage Examples Of HTMLPurifier_Config::loadArrayFromForm