コード例 #1
0
ファイル: form_example.php プロジェクト: johnulist/library
<?php

/**
 * @author		Jesse Boyer <*****@*****.**>
 * @copyright	Copyright (C), 2011-12 Jesse Boyer
 * @license		GNU General Public License 3 (http://www.gnu.org/licenses/)
 *				Refer to the LICENSE file distributed within the package.
 *
 * @link		http://jream.com
 */
require_once '../jream/autoload.php';
new jream\Autoload('../jream/');
if (isset($_REQUEST['run'])) {
    try {
        $form = new jream\Form();
        $form->post('name')->post('agree')->format('checkbox')->post('box')->validate('length', array(1, 25));
        $form->submit();
        $data = $form->get();
        print_r($data);
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
?>

<form action="?run" method="post">
	<input type="text" name="name" value="Jesse" />
	<input type="checkbox" name="agree" />
	<input type="text" name="box" />
	<input type="submit" />
</form>
コード例 #2
0
ファイル: form.php プロジェクト: johnulist/library
* Positive Case
*/
$mimic = array('name' => 'Jesse', 'age' => 27);
try {
    $form = new jream\Form($mimic);
    $form->post('name')->format('ifeq', array('Jesse', 'life'))->validate('matchany', array(1, 2, 3, 4))->validate('greaterthan', 5)->validate('lessthan', 4)->post('age')->validate('digit');
    $form->submit();
    print_r($form->get());
} catch (Exception $e) {
    echo $e->getMessage();
}
try {
    $form = new jream\Form($mimic);
    $form->post('name')->validate('matchany', array('JeSSe', 'Joey', 'jenny'), false)->post('age')->validate('digit');
    $form->submit();
    print_r($form->get());
} catch (Exception $e) {
    echo $e->getMessage();
}
echo '<hr />';
/**
* Negative Cases
*/
try {
    $form = new jream\Form(array('name' => 'Jesse', 'age' => 25));
    $form->post('name')->validate('minlength', 5)->post('age')->validate('greaterthan', 24);
    $form->submit();
} catch (Exception $e) {
    echo $e->getMessage() . '<br />';
}
try {