1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tutorials: update the vweb tutorial with the new form parsing syntax

This commit is contained in:
Alexander Medvednikov 2021-10-12 07:17:49 +03:00
parent da58ba0d5c
commit 555e8cada6

View File

@ -1,4 +1,4 @@
## Building a 150 KB web blog in V with 0 dependencies ## Building a 150 KB web blog in V & SQLite
Hello, Hello,
@ -348,10 +348,9 @@ Create `new.html`:
```v ignore ```v ignore
// article.v // article.v
import vweb import vweb
['/new_article'; post]
pub fn (mut app App) new_article() vweb.Result { [post]
title := app.form['title'] pub fn (mut app App) new_article(title string, text form) vweb.Result {
text := app.form['text']
if title == '' || text == '' { if title == '' || text == '' {
return app.text('Empty text/title') return app.text('Empty text/title')
} }
@ -367,11 +366,11 @@ pub fn (mut app App) new_article() vweb.Result {
} }
``` ```
> Untyped `form['key']` is temporary. Very soon Vweb will accept query and form The decorator on our function tells vweb that it is an HTTP POST type operation.
parameters via function arguments: `new_article(title, text string) {`.
The decorator on our function tells vweb the path to our endpoint, `/new_article`, This time Vweb parses the HTTP form and assigns correct values with correct types to
and that it is an HTTP POST type operation. function arguments, which saves a lot of typing (e.g. `title := app.form['title']` is
not necessary).
We need to update `index.html` to add a link to the "new article" page: We need to update `index.html` to add a link to the "new article" page: