vweb: populate action method params with form values

pull/12154/head
Alexander Medvednikov 2021-10-12 07:09:56 +03:00
parent 4d7bb95c2f
commit da58ba0d5c
3 changed files with 14 additions and 2 deletions

View File

@ -8584,7 +8584,7 @@ fn (mut c Checker) verify_all_vweb_routes() {
continue
}
if f.return_type == typ_vweb_result && f.receiver.typ == m.params[0].typ
&& f.name == m.name {
&& f.name == m.name && !f.attrs.contains('post') {
c.change_current_file(f.source_file) // setup of file path for the warning
c.warn('mismatched parameters count between vweb method `${sym_app.name}.$m.name` ($nargs) and route attribute $m.attrs ($nroute_attributes)',
f.pos)

View File

@ -100,6 +100,9 @@ fn (mut g Gen) comptime_call(node ast.ComptimeCall) {
if m.params.len - 1 != node.args.len && !expand_strs {
// do not generate anything if the argument lengths don't match
g.writeln('/* skipping ${node.sym.name}.$m.name due to mismatched arguments list */')
// g.writeln('println(_SLIT("skipping ${node.sym.name}.$m.name due to mismatched arguments list"));')
// eprintln('info: skipping ${node.sym.name}.$m.name due to mismatched arguments list\n' +
//'method.params: $m.params, args: $node.args\n\n')
// verror('expected ${m.params.len-1} arguments to method ${node.sym.name}.$m.name, but got $node.args.len')
return
}

View File

@ -473,7 +473,16 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) {
// should be called first.
if !route.path.contains('/:') && url_words == route_words {
// We found a match
app.$method()
if req.method == .post {
// Populate method args with form values
mut args := []string{cap: method.args.len}
for param in method.args {
args << form[param.name]
}
app.$method(args)
} else {
app.$method()
}
return
}