From 637ebe5d42bf42045747c1c256c1e277c3fea6dc Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 10 Nov 2021 18:26:16 +0200 Subject: [PATCH] examples: improve examples/vweb/file_upload --- examples/vweb/file_upload/index.html | 1 + examples/vweb/file_upload/submit.html | 12 ++++++++++++ examples/vweb/file_upload/vweb_example.v | 15 ++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 examples/vweb/file_upload/submit.html diff --git a/examples/vweb/file_upload/index.html b/examples/vweb/file_upload/index.html index e191d3962d..d02870e9db 100644 --- a/examples/vweb/file_upload/index.html +++ b/examples/vweb/file_upload/index.html @@ -12,6 +12,7 @@ File form:
+
diff --git a/examples/vweb/file_upload/submit.html b/examples/vweb/file_upload/submit.html new file mode 100644 index 0000000000..1664323228 --- /dev/null +++ b/examples/vweb/file_upload/submit.html @@ -0,0 +1,12 @@ + + +Submitted form info: + +@for name, value in form_data + +

name: @name

+

value: @value

+ +@end + +Back diff --git a/examples/vweb/file_upload/vweb_example.v b/examples/vweb/file_upload/vweb_example.v index bde55c321b..1736183592 100644 --- a/examples/vweb/file_upload/vweb_example.v +++ b/examples/vweb/file_upload/vweb_example.v @@ -2,9 +2,7 @@ module main import vweb -const ( - port = 8082 -) +const port = 8082 struct App { vweb.Context @@ -20,13 +18,20 @@ pub fn (mut app App) index() vweb.Result { ['/upload'; post] pub fn (mut app App) upload() vweb.Result { + dump(app.form) + dump(app.files) fdata := app.files['upfile'] - mut files := []vweb.RawHtml{} - for d in fdata { files << d.data.replace_each(['\n', '
', '\n\r', '
', '\t', ' ', ' ', ' ']) } return $vweb.html() } + +['/submit'; post] +pub fn (mut app App) submit() vweb.Result { + dump(app.form) + form_data := app.form.clone() + return $vweb.html() +}