Reputation: 2669
I would like to know how to retrieve POST fields from a pure html file, without using a class which inherit from cppcms::form. I want the class which implements For example with this class:
std::string Index::main(const std::string &url, const std::map<std::string, std::string> parameters)
{
std::string out = (
"<html>\n"
"<body>\n"
"<form name='test' action='' method='post'>"
"<h1>Hello, put your name here:</h1><br />"
"<input type='text' name='user'>"
"<input type='submit' value='Submit'>"
"</form>"
"</body>\n"
"</html>\n"
);
return out;
}
This method is called in a class which inherit from cppcms::application:
void Engine::main(const std::string &url)
{
std::map<std::string, std::string> params;
pages["/"] = boost::bind(&Index::main, boost::shared_ptr<Index>(new Index), _1, _2);
std::string out = pages[url](url, params); // Call to Index::main
response().out() << out;
}
What I would like to do is retrieving the "user" field and putting it into the "params" map without having to make my Index class inherit from cppcms::form or using the "get" method inside of "post". I want the html files/classes to be completely independents from the cppcms framework. Is it possible? Thank you.
Upvotes: 0
Views: 794
Reputation: 31243
You still want to use cppcms::forms even if you don't use automatic form (HTML) generation.
Why? Many good reasons: CSRF validation, encoding validation, various settings validation, etc, etc, etc.
You can setup the parameters you need like username.name("user") in cppcms::form::widgets
classes but still use forms framework.
cppcms::widgets::text username;
username.name("user");
// validation - what you need
username.non_empty()
// single widget loading
username.load(context());
if(username.validate()) {
myname=username.value();
}
// better as you can handle several widgets at once
cppcms::form frm;
frm.add(username);
...
frm.load(context())
if(frm.validate()) {
...
myname=username.value();
}
Upvotes: 0