Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I e-mail the contents of a form -- without server-side help?

Creating MAILTO Links

How do I e-mail the contents of a form -- without server-side help?

by  EdwardMartinIII  Posted    (Edited  )
In most cases, the contents of a form are best handled by a server-side script, say a Perl or ASP bit of business. But in some cases, you don't need all that. In some cases, you just want a bunch of stuff sent from a form. Nothing fancy or encoded or error-checked, just send the darn data.

This'll do that.

As I mentioned, there's no encryption or error checking or anything like that. Also, it only works if the client box also has an e-mail client that understands the "mailto:" link. Basically, if your client-User can use "mailto:" then they can use this.

Also, I think it might only work in IE. If you find that it works elsewhere, or you want to modify it to work elsewhere, let me know and I'll update this question.

Also, it shares e-mail addresses of the client-User. For most things, I don't think this is a problem. It usually pops up a little warning window that covers these bases.

This is a sample document -- run it and check it out and then modify it as you need for your own application.

Save this as "Sample.html"

Code:
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
    <title>Send Out The Data</title>
    <link rel="stylesheet" href="Style.css" type="text/css"></link>
    <script src="sample.js" type="text/javascript"></script>
  </head>
  <body>
  <h3>Submissions Form</h3>
  <form name="SubmissionForm" action="mailto:HungryMan@DonnerParty.com" enctype="multipart/form-data">
    <table class="Fatscope">
      <tr>
        <td class="DescriptorCell">Function Name:</td>
        <td class="ContentCell"><input type="text" size="100" id="FunctionName"></input></td>
      </tr>
      <tr>
        <td class="DescriptorCell">Module which contains Function:</td>
        <td class="ContentCell"><input type="text" size="100" id="ModuleName"></input></td>
      </tr>
      <tr>
        <td class="DescriptorCell">Module Location:</td>
        <td class="ContentCell"><input type="text" size="100" id="ModuleLocation"></input></td>
      </tr>
      <tr>
        <td class="DescriptorCell">Function Description:</td>
        <td class="ContentCell"><textarea cols="75" rows="5" id="FunctionDescription"></textarea></td>
      </tr>
      <tr>
        <td class="DescriptorCell">Function Parameters:</td>
        <td class="ContentCell"><input type="text" size="100" id="FunctionParameters"></input></td>
      </tr>
      <tr>
        <td class="DescriptorCell">Function Example Call:</td>
        <td class="ContentCell"><input type="text" size="100" id="FunctionExample"></input></td>
      </tr>
      <tr>
        <td class="DescriptorCell">Programmer Name:</td>
        <td class="ContentCell"><input type="text" size="100" id="ProgrammerName"></input></td>
      </tr>
    </table>
    <p class="CenteredContent"><input type="reset" value="Clear All Entries" class="PDButton"></input></p>
  </form>

  <form name="ProxyForm" enctype="text/plain" method="post" action ="mailto:HungryMan@DonnerParty.com?subject=Reuseable Code Library Submission" onsubmit="update_message_body();return true;">
    <p class="CenteredContent"><input type="submit" value="Submit New Function" class="PDButton"></input></p>
    <input type="hidden" id="MessageBody" name="MessageBody"></input>
  </form>
  </body>
</html>

Obviously, this uses an external stylesheet called "Style.css", which you can tell from the class calls, but don't let that bother you -- it's just things like background colors, etc. Also, it should be obvious that I trimmed away a bunch of content that is proprietary, but again, it shouldn't be a problem.

Here's the external JavaScript file, which should be saved as "sample.js":

Code:
function update_message_body()
  // This function composes an e-mail message using the contents of 
  // another form on the same page.
  {
    var FunctionName = document.SubmissionForm.FunctionName.value;
    var ModuleName = document.SubmissionForm.ModuleName.value;
    var ModuleLocation = document.SubmissionForm.ModuleLocation.value;
    var FunctionDescription = document.SubmissionForm.FunctionDescription.value;
    var FunctionParameters = document.SubmissionForm.FunctionParameters.value;
    var FunctionExample = document.SubmissionForm.FunctionExample.value;
    var ProgrammerName = document.SubmissionForm.ProgrammerName.value;
    var CurrentDate = new Date();

    document.ProxyForm.MessageBody.value = "\n\n" + "-= Start of Message =-" + "\n\n"
                                            + "Reuseable Code Library Submission" + "\n\n"
                                            + "Time received: " + CurrentDate + "\n\n"
                                            + "Function Name: " + FunctionName + "\n\n"
                                            + "Module Name: " + ModuleName + "\n\n"
                                            + "Module Location: " + ModuleLocation + "\n\n"
                                            + "Function Description: " + FunctionDescription + "\n\n"
                                            + "Function Parameters: " + FunctionParameters + "\n\n"
                                            + "Function Example Call: " + FunctionExample + "\n\n"
                                            + "Submitted by: " + ProgrammerName + "\n\n" + "-= End of Message =-";
    return true;
  }

So, if the mail client is hooked to the browser right, this ought to send the contents of the form to "HungryMan@DonnerParty.com".

I suggest you change that address. [smile]

Hope that helps!

Edward Martin III
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top