add form_error block
This commit is contained in:
@@ -30,11 +30,7 @@ class AdminController extends BaseAdminController {
|
||||
public function indexAction()
|
||||
{
|
||||
|
||||
$form = $this->getFormBuilder();
|
||||
|
||||
$adminLogin = new AdminLogin();
|
||||
|
||||
$form = $adminLogin->buildForm($form, array())->getForm();
|
||||
$form = $this->getLoginForm();
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
@@ -42,10 +38,7 @@ class AdminController extends BaseAdminController {
|
||||
$form->bind($request);
|
||||
|
||||
if($form->isValid()) {
|
||||
//TODO
|
||||
|
||||
} else {
|
||||
//TODO
|
||||
echo "valid"; exit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,4 +46,13 @@ class AdminController extends BaseAdminController {
|
||||
"form" => $form->createView()
|
||||
));
|
||||
}
|
||||
|
||||
protected function getLoginForm()
|
||||
{
|
||||
$form = $this->getFormBuilder();
|
||||
|
||||
$adminLogin = new AdminLogin();
|
||||
|
||||
return $adminLogin->buildForm($form, array())->getForm();
|
||||
}
|
||||
}
|
||||
@@ -7,4 +7,7 @@
|
||||
<route id="admin" path="/admin">
|
||||
<default key="_controller">Thelia\Admin\Controller\AdminController::indexAction</default>
|
||||
</route>
|
||||
<route id="admin.login" path="/admin/login">
|
||||
<default key="_controller">Thelia\Admin\Controller\AdminController::loginAction</default>
|
||||
</route>
|
||||
</routes>
|
||||
@@ -145,6 +145,33 @@ class Form implements SmartyPluginInterface
|
||||
}
|
||||
}
|
||||
|
||||
public function formError($params, $content, \Smarty_Internal_Template $template, &$repeat)
|
||||
{
|
||||
|
||||
$form = $params["form"];
|
||||
if (! $form instanceof \Symfony\Component\Form\FormView) {
|
||||
throw new \InvalidArgumentException("form parameter in form_error block must be an instance of
|
||||
Symfony\Component\Form\FormView");
|
||||
}
|
||||
|
||||
if (empty($form->vars["errors"])) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if ($repeat) {
|
||||
|
||||
$error = $form->vars["errors"];
|
||||
|
||||
$template->assign("message", $error[0]->getMessage());
|
||||
$template->assign("parameters", $error[0]->getMessageParameters());
|
||||
$template->assign("pluralization", $error[0]->getMessagePluralization());
|
||||
|
||||
|
||||
} else {
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
||||
public function getInstance($name)
|
||||
{
|
||||
if (!isset($this->formDefinition[$name])) {
|
||||
@@ -164,7 +191,8 @@ class Form implements SmartyPluginInterface
|
||||
new SmartyPluginDescriptor("block", "form", $this, "generateForm"),
|
||||
new SmartyPluginDescriptor("block", "form_field", $this, "formRender"),
|
||||
new SmartyPluginDescriptor("function", "form_field_hidden", $this, "formRenderHidden"),
|
||||
new SmartyPluginDescriptor("function", "form_enctype", $this, "formEnctype")
|
||||
new SmartyPluginDescriptor("function", "form_enctype", $this, "formEnctype"),
|
||||
new SmartyPluginDescriptor("block", "form_error", $this, "formError")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
<form action="/admin" method="post" class="well form-inline" {form_enctype form=$form}>
|
||||
{form_field_hidden form=$form}
|
||||
{form_field form=$form.username}
|
||||
{form_error form=$form.username}
|
||||
{$message}
|
||||
{/form_error}
|
||||
<input type="text" class="input" placeholder="{intl l='E-mail address'}" name="{$name}" />
|
||||
{/form_field}
|
||||
{form_field form=$form.password}
|
||||
|
||||
Reference in New Issue
Block a user