add smarty function form_enctype

This commit is contained in:
Manuel Raynaud
2013-06-25 10:48:30 +02:00
parent fe92cc546a
commit 2fb6ec2a7d
3 changed files with 22 additions and 6 deletions

View File

@@ -85,6 +85,7 @@ class Form implements SmartyPluginInterface
Symfony\Component\Form\FormView"); Symfony\Component\Form\FormView");
} }
$template->assign("name", $form->vars["name"]); $template->assign("name", $form->vars["name"]);
$template->assign("value", $form->vars["value"]); $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"]; $form = $params["form"];
@@ -122,6 +123,20 @@ class Form implements SmartyPluginInterface
return array_search("hidden", $formView->vars["block_prefixes"]); 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) public function getInstance($name)
{ {
if (!isset($this->formDefinition[$name])) { if (!isset($this->formDefinition[$name])) {
@@ -140,7 +155,8 @@ class Form implements SmartyPluginInterface
return array( return array(
new SmartyPluginDescriptor("block", "form", $this, "generateForm"), new SmartyPluginDescriptor("block", "form", $this, "generateForm"),
new SmartyPluginDescriptor("block", "form_field", $this, "formRender"), 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")
); );
} }
} }

View File

@@ -33,8 +33,7 @@ class CustomerCreation extends AbstractType
{ {
return $builder->add("name", "text") return $builder->add("name", "text")
->add("email", "email") ->add("email", "email")
->add('age', 'integer') ->add('age', 'integer');
;
} }
/** /**

View File

@@ -7,8 +7,9 @@ An image from asset directory :
<div> <div>
{intl l='An internationalized string'} {intl l='An internationalized string'}
</div> </div>
<form method="post" action="index_dev.php" >
{form name="thelia.customer.creation"} {form name="thelia.customer.creation"}
<form method="post" action="index_dev.php" {form_enctype form=$form} >
{form_field_hidden form=$form} {form_field_hidden form=$form}
{form_field form=$form.email} {form_field form=$form.email}
{intl l='email'} : <input type="text" name="{$name}"> {intl l='email'} : <input type="text" name="{$name}">
@@ -20,8 +21,8 @@ An image from asset directory :
{form_field form=$form.age} {form_field form=$form.age}
{intl l='age'} : <input type="text" name="{$name}"> {intl l='age'} : <input type="text" name="{$name}">
{/form_field} {/form_field}
{/form}
</form> </form>
{/form}
<div> <div>
jQuery data: <span id="jquery_block"></span> jQuery data: <span id="jquery_block"></span>
</div> </div>