diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index 0dbfb5f01..0ddd5229b 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -85,6 +85,7 @@ class Form implements SmartyPluginInterface Symfony\Component\Form\FormView"); } + $template->assign("name", $form->vars["name"]); $template->assign("value", $form->vars["value"]); @@ -95,7 +96,7 @@ class Form implements SmartyPluginInterface } } - public function formRenderHidden($params, $template) + public function formRenderHidden($params, \Smarty_Internal_Template $template) { $form = $params["form"]; @@ -122,6 +123,20 @@ class Form implements SmartyPluginInterface return array_search("hidden", $formView->vars["block_prefixes"]); } + public function formEnctype($params, \Smarty_Internal_Template $template) + { + $form = $params["form"]; + + if (! $form instanceof \Symfony\Component\Form\FormView) { + throw new \InvalidArgumentException("form parameter in form_field block must be an instance of + Symfony\Component\Form\FormView"); + } + + if ($form->vars["multipart"]) { + return sprintf('%s="%s"',"enctype", "multipart/form-data"); + } + } + public function getInstance($name) { if (!isset($this->formDefinition[$name])) { @@ -140,7 +155,8 @@ class Form implements SmartyPluginInterface return array( 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_field_hidden", $this, "formRenderHidden"), + new SmartyPluginDescriptor("function", "form_enctype", $this, "formEnctype") ); } } diff --git a/core/lib/Thelia/Form/CustomerCreation.php b/core/lib/Thelia/Form/CustomerCreation.php index f6215387e..4c70a0177 100644 --- a/core/lib/Thelia/Form/CustomerCreation.php +++ b/core/lib/Thelia/Form/CustomerCreation.php @@ -33,8 +33,7 @@ class CustomerCreation extends AbstractType { return $builder->add("name", "text") ->add("email", "email") - ->add('age', 'integer') - ; + ->add('age', 'integer'); } /** diff --git a/templates/smarty-sample/index.html b/templates/smarty-sample/index.html index ac4ae2a0d..89b1c63d6 100755 --- a/templates/smarty-sample/index.html +++ b/templates/smarty-sample/index.html @@ -7,8 +7,9 @@ An image from asset directory :
{intl l='An internationalized string'}
-
{form name="thelia.customer.creation"} + + {form_field_hidden form=$form} {form_field form=$form.email} {intl l='email'} : @@ -20,8 +21,8 @@ An image from asset directory : {form_field form=$form.age} {intl l='age'} : {/form_field} -{/form}
+{/form}
jQuery data: