PDA

View Full Version : newbie forms processing


leonjay
06-30-2004, 10:56 AM
Can anyone provide a very simple example of the code on both the laszlo side and the vbscript side to demonstrate processing a simple form via .asp rather than jsp. For example: sending e-mail via CDONTS or sending data to an SQL or Access database?

antun
06-30-2004, 02:45 PM
This example sends an email. Here's the ASP code that accepts HTTP POST parameters and returns them as a string:


doSubmit.asp
<%@ Language=VBScript %>
<% Option Explicit %>
<%
'-----------------------------------------------------------------------------
' doSubmit.asp
' Sends an email to a recipient, and returns XML.
'-----------------------------------------------------------------------------
Dim objNewMail
Dim From
Dim ToEmail
Dim Subject
Dim Body
Set objNewMail = Server.CreateObject("CDO.Message")
objNewMail.From = "noreply@foo.com"
objNewMail.To = Request.Form("to")
objNewMail.Subject = Request.Form("subject")
objNewMail.TextBody = Request.Form("message")
objNewMail.Send
Set objNewMail = Nothing
%>
<%= "<response msg='email sent' />" %>


Here's the LZX code that submits values gathered from some text fields:


mailform.lzx
<canvas>

<!-- Dataset to make the HTTP POST request and receive any
XML that was returned -->
<dataset name="msg_ds" type="http"
src="http://localhost/form_submission/doSubmit.asp"
request="false" />

<!-- Datapointer that is triggered by the response -->
<datapointer name="msg_dp" xpath="msg_ds:/response">
<method event="ondata">
mydialog.txt.setText(this.xpathQuery("@msg"));
</method>
<method event="onerror">
mydialog.txt.setText("Error!");
</method>
<method event="ontimeout">
mydialog.txt.setText("Timeout!");
</method>
</datapointer>


<!-- Dialog box -->
<modaldialog name="mydialog" width="300" height="200">
<text name="txt" width="160" align="center" multiline="true" />
<view align="right" layout="axis:x; spacing:20">
<button onclick="parent.parent.close()"
isdefault="true">OK</button>
</view>
<simplelayout spacing="5"/>
</modaldialog>


<!-- Form fields -->
<window title="Compose Message" width="200" height="320"
x="30" y="20">
<simplelayout axis="y" spacing="5" />
<text>To (email):</text>
<edittext name="toEmail" width="160" />
<text>Subject:</text>
<edittext name="subject" width="160" />
<text>Message:</text>
<edittext name="message" width="160" height="100" multiline="true"/>
<button>Send message!
<method event="onclick">
msg_ds.setQueryType("POST");
msg_ds.setQueryParams( { to:parent.toEmail.text,
subject:parent.subject.text,
message:parent.message.text } );
msg_ds.doRequest();
mydialog.open();
mydialog.txt.setText("Sending...");
</method>
</button>
</window>
</canvas>


-Antun

antun
06-30-2004, 02:49 PM
I forgot to add:

This is more than just a bare-bones example - I added in the whole cycle - gathering information from the user, telling the user that something is happening, and triggering a response, along with error handling. You don't need the dialog box for example.

-Antun

leonjay
07-01-2004, 06:21 AM
So I came into work this morning and the first thing a found was your reply to my request from yesterday.

I tried it on my development machine at work and of course I got an error. Before diving too deep into SMTP settings and what not, I remoted to my personal Web server and tried it again from there.
Worked like a charm!
Fabulous!
Thanks so much!

Although Laszlo has increased my desire to start looking at .jsp again, I've been working with .asp for the last few years.

Your hasty response just shaved hours off of today's trial and error time.

Thanks again!

antun
07-01-2004, 09:20 AM
Glad I could help. I had the same issues with ASP - I had to change CDONTS to CDO because I'm on a Windows XP box. If you're not interested in JSPs for your server-side code, and don't like these compatibility issues with ASP, you should check out PHP.

-Antun

raven
07-16-2004, 04:18 AM
Thanks this really helped me as well. I am still trying to plod through the docs, but I was curious. How would you do the layout if you wanted the form to look different?

example
To: edittext box
Subject: box
Message: box

So it was laid out label and edittext on one line instead of two for each instance of info you want to send back? Tried the simplelayout axis=y and axis=x but I am not looking for stairs:)

thx,
M@

Originally posted by antun

<!-- Form fields -->
<window title="Compose Message" width="200" height="320"
x="30" y="20">
<simplelayout axis="y" spacing="5" />
<text>To (email):</text>
<edittext name="toEmail" width="160" />
<text>Subject:</text>
<edittext name="subject" width="160" />
<text>Message:</text>
<edittext name="message" width="160" height="100" multiline="true"/>
[/code]

-Antun [/B]

antun
07-18-2004, 06:08 PM
Thanks this really helped me as well. I am still trying to plod through the docs, but I was curious. How would you do the layout if you wanted the form to look different?

example
To: edittext box
Subject: box
Message: box

There's more than one way :) You could wrap each line in a view, and have a layout act on its subviews (or you could have the subviews permanently spaced a certain number of pixels in):


<simplelayout axis="y" spacing="10" />
<view>
<simplelayout axis="x" spacing="5" />
<text>To:</text>
<edittext />
</view>
<view>
<simplelayout axis="x" spacing="5" />
<text>Subject:</text>
<edittext />
</view>


You would be able to componentize the above into a class (e.g. <textinputfieldwithlabel />). Or you could purely use constraints:


<text name="toLabel">To:</text>
<edittext y="${toLabel.y}"
x="${toLabel.x+toLabel.width+5}" />


Or you could have some variable that was the "margin" of the edittext column that they were constrained to.

You're also free to use a combination of the above.

-Antun

raven
07-18-2004, 06:41 PM
That makes sense. Thanks Antun.

Is the syntax for a button the same as a regular submit?

example:
<form action="something.php">

and the submit will take the data entered and submit it to the something.php page?

M@

antun
07-19-2004, 08:49 AM
You mean an HTML submit button? By default the LZX <button> tag does nothing when clicked - you have to tell it what you want it to do. Now you can make it do an HTTP request (like in the first example above), but note the key difference from HTML is that in Laszlo, the request does not mean a page transition.

Like the example shows, to pass the form information back, you need to use a dataset, set the name/value parameters to the form values you want to pass, and call doRequest().

There's a shortcut too - you can use the LZX form tag that does much of this for you:

http://www.laszlosystems.com/lps-2.1.2/docs/lzx-reference/lz-form.html

-Antun

mkamil
10-12-2005, 12:53 PM
How do I modify the original code you posted above so that when the submit button is pressed, an email is sent directly to me rather than to an asp file?

Much thanks for any help you can provide!!

MK

antun
10-12-2005, 12:57 PM
The OpenLaszlo server cannot send emails - you need the back-end service to do that.

If you want to start the user's email client, you can do:


LzBrowser.loadURL("mailto:me@me.com");


-Antun

ebrentnelson
03-11-2006, 04:56 PM
I am wondering how exactly the <form> tag works in Laszlo. I want to submit the form to a PHP script, but I am unsure how to access the values sent in PHP. Are they sent to the $_POST variable? If so, how can I see what is being sent?

Thanks.

Edit:
===================
Scratched using the form... a lot easier just using a dataset and custom form junk