Last active
August 29, 2015 14:10
-
-
Save chrisguitarguy/25436e46764719aa0f54 to your computer and use it in GitHub Desktop.
A silex app with a repeated field. Try submitting mis-matched values -- `Form::isValid` happily accepts them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"silex/silex": "~1.2", | |
"twig/twig": "~1.16", | |
"symfony/form": "~2.6", | |
"symfony/validator": "~2.6", | |
"symfony/config": "~2.6", | |
"symfony/translation": "~2.6", | |
"symfony/twig-bridge": "~2.6" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ form(form) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
use Silex\Application; | |
use Silex\Provider\FormServiceProvider; | |
use Silex\Provider\TwigServiceProvider; | |
use Silex\Provider\TranslationServiceProvider; | |
use Silex\Provider\ValidatorServiceProvider; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\Validator\Constraint as Assert; | |
$app = new Application(); | |
$app->register(new FormServiceProvider()); | |
$app->register(new TranslationServiceProvider()); | |
$app->register(new ValidatorServiceProvider()); | |
$app->register(new TwigServiceProvider(), [ | |
'twig.path' => __DIR__, | |
]); | |
$app['debug'] = true; | |
$app->match('/', function (Application $app, Request $r) { | |
$form = $app['form.factory']->createBuilder() | |
->add('testing', 'repeated', [ | |
'type' => 'text', | |
'required' => true, | |
]) | |
->add('submit', 'submit') | |
->getForm(); | |
$form->handleRequest($r); | |
if ($form->isValid()) { | |
$val = $form['testing']->getData(); | |
if (null === $val) { | |
return sprintf( | |
'Value is null, repated values did not match but the form was valid? Transformation falure: %s', | |
$form['testing']->getTransformationFailure() | |
); | |
} else { | |
return sprintf('Value is "%s"', $val); | |
} | |
} | |
return $app['twig']->render('index.html.twig', [ | |
'form' => $form->createView(), | |
]); | |
})->method('GET|POST'); | |
$app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment