vweb: populate action method params with form values
							parent
							
								
									4d7bb95c2f
								
							
						
					
					
						commit
						da58ba0d5c
					
				|  | @ -8584,7 +8584,7 @@ fn (mut c Checker) verify_all_vweb_routes() { | ||||||
| 						continue | 						continue | ||||||
| 					} | 					} | ||||||
| 					if f.return_type == typ_vweb_result && f.receiver.typ == m.params[0].typ | 					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.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)', | 						c.warn('mismatched parameters count between vweb method `${sym_app.name}.$m.name` ($nargs) and route attribute $m.attrs ($nroute_attributes)', | ||||||
| 							f.pos) | 							f.pos) | ||||||
|  |  | ||||||
|  | @ -100,6 +100,9 @@ fn (mut g Gen) comptime_call(node ast.ComptimeCall) { | ||||||
| 		if m.params.len - 1 != node.args.len && !expand_strs { | 		if m.params.len - 1 != node.args.len && !expand_strs { | ||||||
| 			// do not generate anything if the argument lengths don't match
 | 			// 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('/* 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')
 | 			// verror('expected ${m.params.len-1} arguments to method ${node.sym.name}.$m.name, but got $node.args.len')
 | ||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -473,7 +473,16 @@ fn handle_conn<T>(mut conn net.TcpConn, mut app T, routes map[string]Route) { | ||||||
| 				// should be called first.
 | 				// should be called first.
 | ||||||
| 				if !route.path.contains('/:') && url_words == route_words { | 				if !route.path.contains('/:') && url_words == route_words { | ||||||
| 					// We found a match
 | 					// 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 | 					return | ||||||
| 				} | 				} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue