From da58ba0d5caf5a0f095026449d91aab89364d465 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 12 Oct 2021 07:09:56 +0300 Subject: [PATCH] vweb: populate action method params with form values --- vlib/v/checker/checker.v | 2 +- vlib/v/gen/c/comptime.v | 3 +++ vlib/vweb/vweb.v | 11 ++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 563bb0e885..fd1d29d836 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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) diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index 2ceb47b374..88494a2ea5 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -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 } diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 2278e0b60b..53ec772b2c 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -473,7 +473,16 @@ fn handle_conn(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 }