From 246e7e8464fa16a5d6e47bdfcc5366485d195d22 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 7 Jul 2020 21:35:56 +0200 Subject: [PATCH] vweb: form error --- vlib/vweb/vweb.v | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index ab6ded1de9..5d2019c674 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -53,6 +53,8 @@ pub mut: headers string // response headers done bool page_gen_start i64 + form_error string + } pub struct Cookie { @@ -353,19 +355,19 @@ fn handle_conn(conn net.Socket, mut app T) { } } mut vars := []string{cap: route_words.len} - + //println('http method = $req.method') $for method in T { ok = true - println('\n\n method = $method urlwords=') - println(url_words) - println('attrs=$attrs') + //println('\n\n method = $method urlwords=') + //println(url_words) + //println('attrs=$attrs') if attrs == '' { // No routing for this method. If it matches, call it and finish matching // since such methods have a priority. // For example URL `/register` matches route `/:user`, but `fn register()` // should be called first. - println('no attrs for ${url_words[0]}') - if url_words[0] == method { + //println('no attrs for ${url_words[0]}') + if (req.method == 'GET' && url_words[0] == method) || (req.method == 'POST' && url_words[0] + '_post' == method) { println('easy match $method') vars = [] app.$method(vars) @@ -522,6 +524,10 @@ pub fn (mut ctx Context) serve_static(url, file_path, mime_type string) { ctx.static_mime_types[url] = mime_type } +pub fn (mut ctx Context) error(s string) { + ctx.form_error = s +} + /* fn readall(conn net.Socket) string {