Forum OpenACS Q&A: HTML in formwidget

Collapse
Posted by xx xx on
I'm trying to allow HTML tags in a formwidget. I'm using ad_form 'formwidget:text(text)'. I tried 'formwidget:text(text),html' but that doesn't seem to work.

How do I specify -html or -allhtml in ad_form or should I use the page_contract somehow?
Furthermore, is it possible to allow the 'class' attribute in these HTML-tags?

Remarks:
I adapted the antispam parameter in acs_kernel to allow 'acronym' (oacs 4.6.3) if that matters.
Using 'text(richtext)' renders some problems with the extra format information that it needs '{html} {format}'

Collapse
2: Re: HTML in formwidget (response to 1)
Posted by Tilmann Singer on
It should be fairly easy to write an html validation for the form builder / ad_form so that you could do formwidget:html(text), but no one has done so yet.

Search in your /api-doc/ for "template::data::validate::" for a list of all datatypes that you can use.

Until someone adds it, you can try to cut the validation block workaround from forums and make it work in your ad_form somehow:

element create message content \
    -label [_ forums.Body] \
    -datatype text \
    -widget textarea \
    -html {rows 20 cols 60 wrap soft} \
    -validate {
        empty {expr ![empty_string_p [string trim $value]]} { [_ forums.lt_Please_enter_a_messag] }
    html { expr {( [string match [set l_html_p [ns_queryget html_p f]] "t"] && [empty_string_p [set v_message [ad_quotehtml [ad_html_security_check $value]]]] ) || [string match $l_html_p "f"] } }
        {}
    }

Collapse
3: Re: HTML in formwidget (response to 1)
Posted by xx xx on
Thanks. You put me in the right direction. It works for me now.

I filed a 'suggestion' (https://openacs.org/bugtracker/openacs/bug?bug%5fnumber=1052). BTW this seems to show a bugtracker bug too.

Collapse
4: Re: HTML in formwidget (response to 1)
Posted by Don Baccus on
This probably shouldn't be an ad_form addition per se as whether or not to allow HTML is a datatype thingy, not an overall thingy that applies to all datatypes (say integer).

Perhaps the "text" datatype should be extended to deal with this?  Of course, we already have the rich text widget that does even smarter things.

Collapse
5: Re: HTML in formwidget (response to 1)
Posted by Don Baccus on
Oh, I see, Til's suggesting a new widget ... that might be reasonable.  Anyway ... we should make this easy to do.