Forum OpenACS Q&A: Adding additional HTML into forms

Request notifications

Posted by Andrew Zeon on

I'm trying to do something simple, but I'm not sure how I can do it. 
I want to put some additional HTML code into a form which is 
generated using a formtemplate. 

This is what my CURRENT calendar looks like: click here

This what I WANT my calendar to look like: click here

As you can see, I want to have some additional lines like "SMS alert 
details - Override default settings here" and "blank means send SMS 

These pages were made by just changing the actual html code. However 
I want to be able to do it in the associated tcl file which is 
"cal-item-new.tcl" (/packages/calendar/www/cal-item-new.tcl).

The form code in this file is:

# Create the form
form create cal_item

element create cal_item calendar_id 
        -label "Calendar ID" -datatype integer -widget hidden -value 

element create cal_item title 
        -label "Title" -datatype text -widget text -html {size 60}

element create cal_item date 
        -label "Date" -datatype date -widget date

element create cal_item time_p 
        -label " " -datatype text -widget radio -options {{{All 
Day Event} 0} {{Use Hours Below:} 1}}

element create cal_item start_time 
        -label "Start Time" -datatype date -widget date -format 
"HH12:MI AM" -optional

element create cal_item end_time 
        -label "End Time" -datatype date -widget date -format 
"HH12:MI AM" -optional

element create cal_item description 
        -label "Description" -datatype text -widget textarea -html 
{cols 60 rows 3 wrap soft}

element create cal_item item_type_id 
        -label "Type" -datatype integer -widget select -options 
[calendar::get_item_types -calendar_id $calendar_id] -optional

element create cal_item repeat_p 
        -label "Repeat?" -datatype text -widget radio -options {{Yes 
1} {No 0}} -value 0

element create cal_item sms_alert 
	-label "Enable SMS Alert?" -datatype text -widget radio 
-options {{Yes 1} {No 0}} -value 0

element create cal_item alert_period 
	-label "Alert Period" -datatype text -html { size 2 } 

element create cal_item mobile_number 
	-label "Mobile Number" -datatype text -html { size 12 } 

Can somebody tell me how I can achieve what I want? I don't want to 
mess around with the actual template. I just want to add additional 
code to the bunch of code I've pasted above.

Thanks so much.
Posted by Andrew Zeon on
Sorry about the formatting... it didn't look like that when I
confirmed it.
Posted by defunct defunct on

The 'correct' way to add formatting to things generated by the forms stuff is to edit/re-create the template.

in acs-templating/resources/forms

you'll see the template currently being used.

I usually just take a copy of this, rename it and apply my edits there...

Doing HTML in tcl scripts is nasty and messy and best to be avoided wherever possible.

Posted by Don Baccus on
Another way to do what Simon's suggesting is to just write the form template directly rather than referencing a general-purpose template in your "formtemplate" tag.

The "right" way depends on whether or not the HTML changes you're making are ones you want to use in a bunch of forms (in which case it makes sense to write a new general-purpose template to put in forms/resources) or changes that are specific to that one specific form you're trying to build.

The documentation for this is a bit sketchy ...

Posted by Andrew Zeon on
Is there a way I can define a new element type? For example, I want to have a line like this is my tcl file:

element create cal_item section1_heading -datatype text -widget heading -option "Section 1" -html {bold underline}

All this would do is put a heading on the form. Really long forms would be sub-divided into sections and you could have a section heading for each section. It would be pretty foolish to have to write the whole template out again when all you want is to put headings so that your form may be divided into sections.

In the template file, you would do something like this:

if @elements.widget@ eq heading>
   formwidget id="section1_heading"

It there are any mechanisms that already exist that allows you to do such a thing, then please let me know.

Posted by Jeff Davis on
There already is a section command.
take a look at acs-templating/www/doc/demo/pay.tcl
(I added the -section bit to the demo when testing the resource templates a while back).
Posted by Stan Kaufman on
I'm trying to contort ad_form to create a UI similar to the one that the old 3.2.5 poll module used to reorder options in a poll. This involved a table containing a series of selects in the left-hand column for the numbering, with a "Reorder" button below them. In the right-hand column of the table was the series of text statements (the poll options) underneath which was a textbox and an "Add" button for creating a new option.

I think this is a great UI for editing things (like surveys) in which elements need to be added and reordered. I've spent all afternoon trying to figure out how to do this with ad_form, and I'm about to conclude that ad_form won't work for this. (Maybe that's why poll hasn't yet been ported from 3.2.5 to 4.x?)

Can anyone who understands ad_form and the templating system better than I (that should include just about everyone) opine whether ad_form can be extended to do this duty, or whether it will require writing html from the .tcl (bleah!). TIA!

Posted by Don Baccus on
You could store the form building snippets in a list that you then reorder. Using ad_form to build it you could do something like

foreach form_element $form_elements {
    ad_form -extend -name your_form_name -form $form_element

ad_form -extend -name your_form_name -new_data {
} -edit_data {

(or -on-submit or whatever you do to handle the form submission)

This presumes that you've already put out some initial form information because of the use of -extend.

I've not tried this because, frankly, I hadn't thought about the problem when writing ad_form. But I don't see any reason offhand why it won't work.

Posted by Dave Bauer on

You have several options:

Create a new form template and use that template with the form.

Build the formtemplate in the adp file.

Create a new widget to be used with the templating system.

I know all these are valid options, but I am not sure of the exact way to go about doing it.

It looks like that page formats the fields in a table and has multiple submit buttons. I am just getting this from the code. Can you post a screenshot or link to a sample page?

Posted by Stan Kaufman on
Thanks for the ideas Don & Dave; I want to swim with the current here and not against it.

Some combination of form elements "-extend"ed into the form, custom widgets and specialized templates should do the trick.

Dave, looks like I can't paste a screenshot right here in this thread, but if you go to the "Testing Group" where you had a look at my questionnaire module, you can see the admin UIs for both it and the Poll module.

Here's the url: If anyone else is interested, email me and I'll add you to that particular group (it's not a public one and I'm running it in "closed" mode) or else put up some screenshots.