tutorials: update the vweb tutorial with the new form parsing syntax
parent
da58ba0d5c
commit
555e8cada6
|
@ -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:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue