Forum OpenACS Q&A: Passing information from a form to another adp?

Hi,

Im a newbie to OpenACS and Roberto Mello has kindly helped me a 
little with my problem, however im still getting a file-not-
found.html error when i try run this. Forgive me for the long post 
with the code but its best if i show the whole picture.

Ive got compose.tcl/adp files which is a form to take the params for 
sending an email and ive got ending.tcl/adp files which are meant to 
take the input from the form and send the email via the send_mail 
function (from my webmail-procs.tcl file). I can fill in the form but 
then when I send it, it goes wrong. I think the problem is to do with 
the @...@ for the params as im confused as to where they are meant to 
go. And it could be also to do with the form as Im not sure if i 
should be using the formtemplate or form and whether im using it 
right.

Ok, heres the code - any help would be greatly appreciated and an 
explanation would be more than appreciated.

__________________________________________________________________

compose.adp

master src="master-template">
property name="title">@page_title@

html>
head>
  style>
    h3 { font-family: Arial, Helvetica }
    th { font-family: Arial, Helvetica }
    td { font-family: Arial, Helvetica }
  /style>
/head>

center>
body>

formtemplate id="compose_email" action="@target@">

table>
tr>
  td>Sender
  td>
/tr>
tr>
  td>Recipients
  td>
/tr>
tr>
  td>Subject
  td>
/tr>
tr>
  td>Body
  td>
/tr>
/table>

center>
input type=submit value="@submit_label@">
/center>

/formtemplate>
/center>

/html>

__________________________________________________________________

compose.tcl

# Create form

form create compose_email

element create compose_email sender -datatype text 
  				    -html { size 50 } 
				    -label "Sender"
  
element create compose_email recipients -datatype text 
  					-html { size 50 } 
					-label "Recipients"
					  
element create compose_email subject -datatype text 
  				     -html { size 50 } 
				     -label "Subject"
				       
element create compose_email body -widget textarea 
				  -datatype text 
				  -html { cols 48 rows 8 wrap soft } 
				  -label "Body"

# Set values

set from "testing@hotmail.com"
set to "mo2mo@hotmail.com"

if { [form is_request compose_email] } {
	element set_properties compose_email sender -value $from
        element set_properties compose_email recipients -value $to
}

set page_title "Composing an email"
set submit_label "Send"
set target "sending"

__________________________________________________________________

sending.tcl


send_mail { @sender@ @recipients@ @subject@ @body@ }

set page_title "Sending email"

__________________________________________________________________

sending.adp

html>

!-- I dont really need anything here do I? -->

Mail sending

/html>

__________________________________________________________________

webmail-procs.tcl


proc send_mail { sender recipients subject body } {

  ns_write "Starting the ns_sendmail command...

"

  if [catch { ns_sendmail $recipients $sender $subject $body } 
errmsg] {
	ns_write "Failed sending email to $recipients: $errmsg"
  }

  ns_write "
Ending the ns_sendmail command...
"
}

__________________________________________________________________


Thank you very much for any help, advice and guidance.
Ayman



PS: How can you display HTML on the bboard if youve selected HTML to 
use the pre tag? Any overidding mechanism? I just chopped off 
the beginning of each tag - doesnt seem the best way to do it.
Collapse
Posted by Ayman M on
This got cut out of the last post...

in compose.adp the following should be there:

formwidget id="sender">
formwidget id="recipients">
formwidget id="subject">
formwidget id="body">

each one for their corresponding section.

Collapse
Posted by Ayman M on
Is it something to do with ad_page_contract and ad_return_template? Any help would be greatful.

Ayman
send_mail { @sender@ @recipients@ @subject@ @body@ }

this is definitely bad. @vars@ are for use in adp files. in the tcl file use $var. and do not use {} here, anything within {} is not evaluated.

send_mail $sender $recipients $subject $body

It's easier to make the target page of the form the same as the page that the form is in, "compose" in your example. In compose.tcl add a code block like this

if { [form is_valid compose_email] } {
   ... code from sending.tcl comes here ...
   ad_returnredirect "sent"
}

remove the explicit setting of action/target, and add a simple sent.adp that does nothing except telling the user that the mail has been sent. Among many other things this has the side effect that a reload of the resulting page doesn't send the mail another time.

Examples for the templating form code can be seen in the notes package.

Also you might want to look into ad_form (try /api-doc/proc-view?proc=ad_form on your server), the new way to do this kind of stuff.