Esempio n. 1
0
 public function testIntents()
 {
     $code = Phorms\Csrf::generate('/okay', 60);
     $this->assertFalse(Phorms\Csrf::check($code, '/fail'));
     $this->assertTrue(Phorms\Csrf::check($code, '/okay'));
 }
Esempio n. 2
0
File: index.php Progetto: qix/phorms
<?php

require __DIR__ . '/vendor/autoload.php';
session_start();
Phorms\Csrf::setSecret('mysecret');
$form = new Phorms\Form(array('@fieldset:Your details', 'firstname' => 'Firstname', 'surname' => 'Surname', 'email' => ['Email', 'type' => 'email', 'required' => True], 'color' => ['Color', ['green' => 'Green (good)', 'red' => 'Red (bad)']], 'movie' => ['Movies', [116 => 'Braveheart', 327 => 'The Rock', 955 => 'Alien II'], 'multiple' => True], 'happy' => ['Happy', 'type' => 'checkbox'], '@fieldset:Action(s)', '@submit:Create account'));
print '<html><head><link rel="stylesheet" type="text/css" href="style.css"></head><body>';
if ($data = $form->data()) {
    if ($errors = $form->check($data)) {
        print '<p>We encountered the following errors:<ul>';
        foreach ($errors as $message) {
            if (is_string($message)) {
                print '<li>' . htmlentities($message) . '</li>';
            }
        }
        print '</ul>';
    } else {
        print "Thank you " . htmlentities($data['firstname']) . "!";
        print '<pre>' . htmlentities(var_export($data, True)) . '</pre>';
        // You could exit at this point, or just re-render the form with the data
        print '<hr/>';
    }
}
$form->render($data);
print '</body></html>';