On Sun, Jan 2, 2011 at 8:40 PM, Dexter <[email protected]> wrote:
> has a condition which says "$if not form.valid:" The documentation
> does describe what form.validates() is but could not get any idea what
> form.valid checks for ...

So ok. Not nice of us to leave these unanswered.

form.valid means that you've run form.validates() and that the form
contents are valid. It's a property of the form object.

The usage in the article is not very clever. You should test if the
fields contains the error messages (if I remember correctly, there
should be a notes property on each field), and then display the notes
as error messages in your template code. Alternatively, if you're
using the form.render() method, this is done automatically for you.

The real use case scenario for form.valid would be something else, but
I'll leave that up to your imagination. I never needed to do that in
templates.

> Also what is the significance of the ":" in $:form.render(). As per
> the documents it is used to avoid escaping of HTML code. Here form is
> a python object right and we call an associated function. Why do we
> need the colon there ?

$ outputs the results of statements and expressions. It automatically
escapes any HTML tags to prevent XSS attacks. However, sometimes you
do want to output HTML, and that's what colon is for. It must appear
right after the $ sign.


-- 
Branko Vukelic

[email protected]
http://www.brankovukelic.com/

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to