RejectedSoftware Forums

Sign up

req.form is empty

static this()
{
	auto h = new Handlers;
	
	setLogLevel(LogLevel.Debug);
	setLogFile("log.txt", LogLevel.Info);
	
	auto settings = new HttpServerSettings;
	//settings.hostName = "realty.com";
	settings.port = 8080;
	settings.bindAddresses = ["127.0.0.1"];
	settings.errorPageHandler = &h.error;
	
	auto router = new UrlRouter;
	
	router.get("/", &h.listHandler);
	router.get("/apartment", &h.dumbHandler);
	router.get("*", serveStaticFiles("./public/"));
	
	listenHttp(settings, router);
}

/// member of class h:
        void dumbHandler(HttpServerRequest req, HttpServerResponse res)
	{
		render!("apartment.dt", req)(res);
	}

apartment.dt template:

extends layout

block content
    h1 #{ req.form }

url looks like: http://127.0.0.1:8080/apartment?id=123&qwe=123
this code always returns: []
why? I am can not get any arguments because this.

Re: req.form is empty

Am 10/24/2012 12:06 PM, schrieb denizzzka:

static this()
{
    auto h = new Handlers;
    
    setLogLevel(LogLevel.Debug);
    setLogFile("log.txt", LogLevel.Info);
    
    auto settings = new HttpServerSettings;
    //settings.hostName = "realty.com";
    settings.port = 8080;
    settings.bindAddresses = ["127.0.0.1"];
    settings.errorPageHandler = &h.error;
    
    auto router = new UrlRouter;
    
    router.get("/", &h.listHandler);
    router.get("/apartment", &h.dumbHandler);
    router.get("*", serveStaticFiles("./public/"));
    
    listenHttp(settings, router);
}

/// member of class h:
       void dumbHandler(HttpServerRequest req, HttpServerResponse res)
    {
        render!("apartment.dt", req)(res);
    }

apartment.dt template:

extends layout

block content
   h1 #{ req.form }

url looks like: http://127.0.0.1:8080/apartment?id=123&qwe=123
this code always returns: []
why? I am can not get any arguments because this.

req.query contains the parameters of a query string form (req.form
is for POST forms). I'll improve the docs there.

Re: req.form is empty

Thanks, it is works!

Re: req.form is empty

On Wed, 24 Oct 2012 11:27:59 +0200, Sönke Ludwig wrote:

req.query contains the parameters of a query string form (req.form
is for POST forms). I'll improve the docs there.

How I can check what req.form["field"] is unset?
Otherwise it cause range violation if I attempt to access to them.

Re: req.form is empty

Am 27.10.2012 14:30, schrieb denizzzka:

On Wed, 24 Oct 2012 11:27:59 +0200, Sönke Ludwig wrote:

req.query contains the parameters of a query string form (req.form
is for POST forms). I'll improve the docs there.

How I can check what req.form["field"] is unset?
Otherwise it cause range violation if I attempt to access to them.

You can use the in or !in operators, or use req.form.get("field",<br>"default value"):

if( auto pvalue = "field" in req.form )
    logInfo("Field value: %s", *pvalue);

Re: req.form is empty

On Sat, 27 Oct 2012 21:09:00 +0200, Sönke Ludwig wrote:

Am 27.10.2012 14:30, schrieb denizzzka:

On Wed, 24 Oct 2012 11:27:59 +0200, Sönke Ludwig wrote:

req.query contains the parameters of a query string form (req.form
is for POST forms). I'll improve the docs there.

How I can check what req.form["field"] is unset?
Otherwise it cause range violation if I attempt to access to them.

You can use the in or !in operators, or use req.form.get("field",<br>"default value"):

if( auto pvalue = "field" in req.form )
    logInfo("Field value: %s", *pvalue);

Thanks, it works