diff --git a/form/file_tag.go b/form/file_tag.go
new file mode 100644
index 0000000..01ebd08
--- /dev/null
+++ b/form/file_tag.go
@@ -0,0 +1,13 @@
+package form
+
+import "github.com/gobuffalo/tags"
+
+func (f Form) FileTag(opts tags.Options) *tags.Tag {
+ if opts["type"] == nil {
+ opts["type"] = "file"
+ }
+ if opts["type"] == "file" {
+ f.Options["enctype"] = "multipart/form-data"
+ }
+ return f.InputTag(opts)
+}
diff --git a/form/input_tag.go b/form/input_tag.go
index 5bc0382..b8067e8 100644
--- a/form/input_tag.go
+++ b/form/input_tag.go
@@ -6,6 +6,9 @@ func (f Form) InputTag(opts tags.Options) *tags.Tag {
if opts["type"] == nil {
opts["type"] = "text"
}
+ if opts["type"] == "file" {
+ f.Options["enctype"] = "multipart/form-data"
+ }
return tags.New("input", opts)
}
diff --git a/form/input_tag_test.go b/form/input_tag_test.go
index f6a9443..f274935 100644
--- a/form/input_tag_test.go
+++ b/form/input_tag_test.go
@@ -28,3 +28,11 @@ func Test_Form_DateTimeTag(t *testing.T) {
})
r.Equal(``, i.String())
}
+
+func Test_Form_InputTag_File(t *testing.T) {
+ r := require.New(t)
+ f := form.New(tags.Options{})
+ i := f.InputTag(tags.Options{"type": "file"})
+ r.Equal(``, i.String())
+ r.Equal(f.Options["enctype"], "multipart/form-data")
+}