Skip to content

Instantly share code, notes, and snippets.

@leftdevel
Created May 10, 2012 22:14
Show Gist options
  • Save leftdevel/2656240 to your computer and use it in GitHub Desktop.
Save leftdevel/2656240 to your computer and use it in GitHub Desktop.
<?php
/**
* Este es el action donde se envió el formulario.
*/
public function paso2Action()
{
$object = new Object();
$request = $this->getRequest();
$form = $this->createForm(new ObjectType(), $object);
$form->bindRequest($request);
// Si la cuenta es nueva o existente, establecer el validation_group necesario
$validation_group = true === $object->getUseExisting()
? 'no_validar_username_password'
: 'si_validar_username_password';
// Volver a crear el formulario de modo que se utilice el validation_group adecuado
$form = $this->createForm(new ObjectType(), $object, array(
'validation_groups' => array($validation_group),
));
$form->bindRequest($request); // Vuelve la mula al trigo :D
if (true === $form->isValid()) { // Esto debe validar acorde al grupo que se le pasó como argumento
// Hacer lo que sea necesario...
// Persistir.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment