Lasso Soft Inc. > Home

  • Articles

 

Lasso Basics - Email Contact Form - Part 1

Originally sourced from the tip of the week for March 23, 2007, this article shows how to create an email contact form using Lasso. The tip demonstrates a basic technique which is used on many sites. The tip includes instructions for a simple contact form and several variations including sending email to multiple recipients, sending HTML formatted email, and sending attachments with the email.

Introduction

An email contact form is one of the simplest methods of allowing site visitors to contact you. It is very easy for site visitors to use and doesn't require that you give out your email address so there is no risk of your address being harvested for spam.

Your contact form can be simple with just options for the visitor's name, email address, and a contact. Or, it can be more complex with survey questions or the ability to upload a file for you to review. This tip shows how to create a simple email form and then how to embellish it with additional questions.

The email message which you send can be addressed to a single team member or to many. You can use bare bones text formatting if the email is intended just for you. Or, you can create nice looking HTML messages for a client. This tip shows how to address an email message to several recipients and how to use HTML formatting to create a nice looking email message.

Finally, you can allow the site visitor to upload a file and include that file as an attachment with your email message. This tip shows how to modify the simple contact form with a "file" input and the simple code necessary to attach the uploaded file to the email message.

Note - This tip assumes that you are going to be sending email to yourself or to one or more predefined email addresses. If you want to send email to the site visitor or to create a send to a friend feature it is important to take steps to prevent your email form being used to send spam.

NEEDS a downloadable to USE the EXAMPLES

Simple Email Form

The code for a very simple email form is shown below. A working example of this form can be found in the download in the "simple.lasso" file. You should replace the email address "example@example.com" with your own email address to test the form.

The form uses the Lasso tag [Response_FilePath] as its action. This instructs the browser to reload the current page when the form is submitted. The form includes three inputs. Text inputs allow the visitor to enter their name and email address and a textarea allows the visitor to enter as long a comment as they need.

<form action="[Response_FilePath]" method="post">

  <input type="hidden" name="action" value="submit" />  

  <h2>Contact Us</h2>

  [If: (Action_Param: 'action', -Count) != '']

    <p>Thank you. We will respond to your message shortly.</p>

  [Else]

  <p>Use this form to send us an email message.</p>

  <p>Your Name:<br />

    <input type="text" name="name" value="" /></p>

  <p>Your Email Address:<br />

    <input type="text" name="email" value="" /></p>

  <p>Comments:<br />

    <textarea name="comments" rows="10" cols="40"></textarea></p>

  <p><input type="submit" name="action" value="Submit" />

  [/If]

 

When the site visitor fills out the form and submits it, the browser posts the values from the form back to the Web server. The following LassoScript appears at the top of the "simple.lasso" file. The conditional checks whether an "action" was specified in the posted form data. The code within the conditional will not execute the first time the page is loaded by a visitor, but will execute after they fill out the form and hit the "Submit" button.

If: (Action_Param: 'action', -Count) > 0;
    Email_Send: -To='example@example.com',
      -From='example@example.com',
      -Subject='Email Form - Simple',
      -Body='The following form was submitted on your Web site:rr' +
        'Name:r' + (Action_Param: 'name') + 'rr' +
        'Email:r' + (Action_Param: 'email') + 'rr' +
        'Comments:r' + (Action_Param: 'comments') + 'rr' +
        'Date/Time:r' + Date + 'rr' +
        'Client:r' + Client_IP + ' ' + Client_Type + 'rr';
 /If;

 

The [Email_Send] tag sends an email to the address "example@example.com" with a subject of "Email Form - Simple" and a body that is assembled using several [Action_Param] tags. An example of the received email is shown below.

Multiple Recipients

It is easy to modify the simple form to send messages to several recipients. If you specify multiple email addresses in the -To parameter of the [Email_Send] tag then Lasso will send the message to each of those people. The following message will be sent to "example@example.com" and to "john_doe@example.com".

 

The following form was submitted on your Web site:

  Name:Fletcher

  Email:fletcher@lassosoft.com

  Comments:This is a great Web form.

  Date/Time: 03/23/2007 15:17:20

  Client: 127.0.0.1 Mozilla/5.0 AppleWebKit/419 Safari/419.3

 

One final detail. The form inputs in the HTML shown above are surrounded by a conditional [If: (Action_Param: 'action', -Count) != ''] ... [/If]. This conditional shows a "Thank You" message after the form is submitted rather than showing the form again.

  Email_Send: -To='example@example.com, john_doe@example.com',

    -From='example@example.com',

    -Subject='Email Form - Simple',

    -Body='The following form was submitted on your Web site:\r\r' +

      'Name:\r' + (Action_Param: 'name') + '\r\r' +

      'Email:\r' + (Action_Param: 'email') + '\r\r' +

      'Comments:\r' + (Action_Param: 'comments') + '\r\r' +

      'Date/Time:\r' + Date + '\r\r' +

      'Client:\r' + Client_IP + ' ' + Client_Type + '\r\r';

 

You can also add -CC or -BCC parameters to the [Email_Send] tag. Or, you can put multiple [Email_Send] tags into the conditional in order to send completely different messages to different recipients.

Survey Questions

You can add survey questions to your form by adding text inputs, select lists, radio buttons, or checkboxes. For example, you might just just like to collect information about what kind of customer the site visitor is.

A working example of this form can be found in the download in the "survey.lasso" file. You should replace the email address "example@example.com" with your own email address to test the form.

The following form adds several survey questions to the simple form shown above. These include a pop-up menu so the visitor can select an email topic, a set of radio buttons so the visitor can select how long they've been using the product, and a set of checkboxes so the visitor can select what platform they use.

input type="hidden" name="action" value="submit" />  

  <h2>Contact Us</h2>

  [If: (Action_Param: 'action', -Count) != '']

    <p>Thank you. We will respond to your message shortly.</p>

  [Else]

  <p>Use this form to send us an email message.</p>

  <p>Your Name:<br />

    <input type="text" name="name" value="" /></p>

  <p>Your Email Address:<br />

  <input type="text" name="email" value="" /></p>

  <p>Topic:<br />

    <select name="topic">

      <option>General Feedback</option>

      <option>Sales Question</option>

      <option>Technical Support</option>

    </select></p>

  <p>Comments:<br />

    <textarea name="comments" rows="10" cols="40"></textarea></p>

  <p>How long have you been using our product?<br />

    <input type="radio" name="howlong" value="1 year" />1 year

    <input type="radio" name="howlong" value="2 years" />2 years

    <input type="radio" name="howlong" value="3 years" />3 years

    <input type="radio" name="howlong" value="4 years" />4 years or more

  <p>What platforms do you use?<br />

    <input type="checkbox" name="platform" value="Macintosh" />Macintosh

    <input type="checkbox" name="platform" value="Windows" />Windows

    <input type="checkbox" name="platform" value="Linux" />Linux

    <br /><input type="checkbox" name="platform" value="Other" />Other       

    <input type="text" name="platform" value="" />

  <p><input type="submit" name="action" value="Submit" />

  [/If]

 

An example of the received email is shown below. The topic, e.g. "Sales Question" will be shown as the subject of the email message.

 

The following form was submitted on your Web site:


  Name:Fletcher

  Email:fletcher@lassosoft.com

  Comments: How much does it cost?

  How Long:2 years

  Platform:Macintosh
           Windows
           Linux
           Other
           Amiga

  Date/Time: 03/23/2007 15:17:20
  Client: 127.0.0.1 Mozilla/5.0 AppleWebKit/419 Safari/419.3

Email Contact Form Part 2 HTML Formatting



Author: Fletcher Sandbeck
Created: 23 Mar 2007
Last Modified: 16 Mar 2011

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft