Re: [Cppcms-users] working with http::context.
Brought to you by:
artyom-beilis
|
From: augustin <aug...@ov...> - 2010-08-24 15:13:28
|
On Tuesday 24 August 2010 09:07:21 pm Artyom wrote:
> If entry form fails validation you may just display any message you want
> outside widgets system. i.e.
>
> if(request().request_method()=="POST") {
> my_content.my_form.load(context());
> if(!my_content.my_form.validate()) {
> my_content.fail_flag = true;
> }
> }
>
> And in template system itself
>
> <% if fail_flag %>
> <strong>FAILED</strong>
> <% end %>
> <form ... >
> <% form as_p my_form %>
> </form>
>
Thank you, Artyom.
That's not exactly what I wanted to do, but you put me back on the right
track.
I wanted to be able to add messages for the user from within
my_content.my_form.validate().
What I did is create a struct to hold messages:
struct user_messages {
std::list<std::string> messages;
};
I add this struct to my base_content and pass it by reference to
my_content.my_form.validate() so that I can populate it with actual messages
according to the validation process.
Then I can output it within the template using a foreach loop.
There may be better ways, but it works for now. When I have more experience, I
might come up with a more elegant solution.
> See example of forms.
Yes, I had studied it closely. Your examples are very useful and I reproduced
them to learn from them.
> Also you can specify a number of reasons
> and add some flag to form you are created.
I am not too sure what you are referring to, here.
> No, http::context just preservers specific information for single
> request/response. You can't change or alter it.
Ok. That was my mistake. I was trying to store temporary data (i.e. data
related to the current request only) somewhere in http::context instead of
putting it into my class derived from cppcms::base_content, as you suggested
above.
Anyway, your reply was very useful, as usual, and I managed to do more or less
what I wanted. Thank you.
Augustin.
--
Friends: http://www.reuniting.info/ http://activistsolutions.org/
My projects:
http://astralcity.org/ http://3enjeux.overshoot.tv/ http://linux.overshoot.tv/
http://overshoot.tv/ http://charityware.info/ http://masquilier.org/
http://openteacher.info/ http://minguo.info/
http://www.wechange.org/ http://searching911.info/
.
|