Forum OpenACS Development: losing data from richtext after ad_form validation

Hi,
I have created an ad_form with a richtext and a text fields. I have the text field as a required field. When I enter a long text in the richtext field and nothing in the text field and submit the form, I get error stating that the text field is a required field and there is only the first word in the richtext field. Does anybody know why richtext field value gets lost during validation?

In the edit_request block I do have
set var [template::util::richtext::create $var text/html], which helps with displaying the data from database into the richtext field.

Thanks,
Priya

Collapse
Posted by Antonio Pisano on
Hello Priya,

could you tell me if you build your fields using ad_form or by direct template::* commands?

Also, what version of OpenACS are you running on?

I had some problem with richtext fields some time ago because I didn't consider that they are not a single value, but in fact a list of {content mime_type}. Maybe this is related to your issue.

Collapse
Posted by Priya Rao on
Hi Antonio,
Thanks for the response. I am using ad_form and OpenACS version is 5.8.0.

Here is how I am using it:

ad_form -name user_info -form {
{user_id:key}
{name:text(inform) {label "Name :"} }
{interest:text(richtext) {label "Narrative :"} }
{keywords:text(text) {label "Keywords :"} }
} -edit_request {

# Get interest for the main site.
db_0or1row get_interest_and_keywords { }
set interest [template::util::richtext::create $interest text/html]

} -mode display -edit_data {

# Insert or Update research narrative

} -after_submit {

}


Thanks,
Priya

Collapse
Posted by Antonio Pisano on
I think the guilty here is "display" set on the mode flag. If you change it to "edit", everything should work fine. Is there a reason why you set it on "display"?

From docs, it states that when a button is clicked, form should switch to edit mode automatically, but I don't know exactly what this should mean... Actually, I don't know if the behavior you have shown is correct either... form should not swallow your text whatever mode you give it.

Anyway, that should fix your problem.

All the best

http://www.openacs.org/api-doc/proc-view?proc=ad_form&source_p=1

Collapse
Posted by Gustaf Neumann on
Actually, i was able to reproduce the behavior with and without the display mode. It seems, that one needs to refresh the field on validation errors. For example in the cases where xowiki uses ad_form, this does not seem to be necessary. However, the example below should be sufficiently simple to be adapted for other needs.

best regards
-gustaf neumann

ad_page_contract {
    demo page
} {
    {name "Charlie Brown"}
    {interest:html "lying on the roof with snoopy"}
    {interest_format text/html}
    {keywords ""}
}

set form_name user_info
ad_form -name $form_name -form {
    {name:text(inform) {label "Name :"} }
    {interest:text(richtext) {label "Narrative :"} }
    {keywords:text(text) {label "Keywords :"} }
} -mode display -after_submit {
    ns_log notice "final value of interest <$interest> format $interest_format"
    ad_returnredirect /
    ad_script_abort
} -on_request  {
    set interest [list $interest $interest_format]
} -on_validation_error {
    template::element::set_value $form_name interest [list $interest $interest_format]
} 

set title "Demo Page"
set context [list $title]
Collapse
Posted by Priya Rao on
Thanks a lot Gustaf.

on_validation_error block code has solved the issue.

Priya