Save Form Data to file

  • Thread starter Thread starter glbdev
  • Start date Start date
G

glbdev

Hello.

Does anyone have any example code of how to save a form, once it is
submitted, as a text document? What I mean is that I want to save
the form (with HTML tags) to a text file which I can than eMail to the
person who filled out the form.

I looked around but I can't really find a good example of this.

Any help would be appreciated.

Thanks,
Steve
 
Hello.

Does anyone have any example code of how to save a form, once it is
submitted, as a text document? What I mean is that I want to save
the form (with HTML tags) to a text file which I can than eMail to the
person who filled out the form.

I looked around but I can't really find a good example of this.

Any help would be appreciated.

Thanks,
Steve

You could use Javascript to get the html between the body tags. Then either
set a hidden text field to the html and let the page handle the save of the
file and the email or write a web service to take the hmtl and save the file
and email it to the user.

Hope this helps
Lloyd Sheen
 
You could use Javascript to get the html between the body tags.  Then either
set a hidden text field to the html and let the page handle the save of the
file and the email or write a web service to take the hmtl and save the file
and email it to the user.

Hope this helps
Lloyd Sheen


Thanks for responding. I am not sure how to do this. Do you know of
a link or something that could help?

Steve
 
You could use Javascript to get the html between the body tags. Then
either
set a hidden text field to the html and let the page handle the save of
the
file and the email or write a web service to take the hmtl and save the
file
and email it to the user.

Hope this helps
Lloyd Sheen


Thanks for responding. I am not sure how to do this. Do you know of
a link or something that could help?

Steve

Steve,

I am including some code as a sample:

First is the code for a sample page. The important part is the
validateRequest="false" which is part of the @Page tag. Since you will be
placing HTML into a hidden field ASP.NET will check these field to ensure
that hackers are not messing up your HMTL. In this example and perhaps in
what you are doing this is ok to set to false since you know that it is you
that is doing this.

This is the markup for the page.


<%@ Page Language="VB" validateRequest="false" debug="true"
AutoEventWireup="false" CodeFile="TestGetHTML.aspx.vb"
Inherits="TestGetHTML" %>

<!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" >
<head runat="server">
<title>Untitled Page</title>
</head>

<body>
<script language="javascript">
function SetHMTLToHidden()
{
debugger;
var temp;
var hidden;
temp=document.getElementById('AllTheHTML');
hidden=document.getElementById('HiddenField1');
hidden.value=temp.innerHTML;
}
</script>
<form id="form1" runat="server">
<div id="AllTheHTML">
<table style="width: 656px; height: 176px">
<tr>
<td style="width: 100px">Cell 1</td>
<td style="width: 100px">Some text</td>
<td style="width: 100px"></td>
</tr>
<tr>
<td style="width: 100px"></td>
<td style="width: 100px"></td>
<td style="width: 100px">The middle</td>
</tr>
<tr>
<td style="width: 100px">Cell3</td>
<td style="width: 100px">Somemore text</td>
<td style="width: 100px"></td>
</tr>
</table>
<br />
<asp:HiddenField ID="HiddenField1" runat="server" />
<br />
<asp:Button ID="Button1" runat="server"
OnClientClick="SetHMTLToHidden();" Text="Button" />
</div>
</form>
</body>
</html>


This is a sample of a code behind which gets the HTML from the hidden field
and then you do with it as you want.



Partial Class TestGetHTML
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim txt As String
txt = Me.HiddenField1.Value

End Sub
End Class

Hope this helps
Lloyd Sheen
 
Thanks Lloyd!! I will try this out.

Steve

Lloyd said:
Thanks for responding. I am not sure how to do this. Do you know of
a link or something that could help?

Steve

Steve,

I am including some code as a sample:

First is the code for a sample page. The important part is the
validateRequest="false" which is part of the @Page tag. Since you will be
placing HTML into a hidden field ASP.NET will check these field to ensure
that hackers are not messing up your HMTL. In this example and perhaps in
what you are doing this is ok to set to false since you know that it is you
that is doing this.

This is the markup for the page.


<%@ Page Language="VB" validateRequest="false" debug="true"
AutoEventWireup="false" CodeFile="TestGetHTML.aspx.vb"
Inherits="TestGetHTML" %>

<!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" >
<head runat="server">
<title>Untitled Page</title>
</head>

<body>
<script language="javascript">
function SetHMTLToHidden()
{
debugger;
var temp;
var hidden;
temp=document.getElementById('AllTheHTML');
hidden=document.getElementById('HiddenField1');
hidden.value=temp.innerHTML;
}
</script>
<form id="form1" runat="server">
<div id="AllTheHTML">
<table style="width: 656px; height: 176px">
<tr>
<td style="width: 100px">Cell 1</td>
<td style="width: 100px">Some text</td>
<td style="width: 100px"></td>
</tr>
<tr>
<td style="width: 100px"></td>
<td style="width: 100px"></td>
<td style="width: 100px">The middle</td>
</tr>
<tr>
<td style="width: 100px">Cell3</td>
<td style="width: 100px">Somemore text</td>
<td style="width: 100px"></td>
</tr>
</table>
<br />
<asp:HiddenField ID="HiddenField1" runat="server" />
<br />
<asp:Button ID="Button1" runat="server"
OnClientClick="SetHMTLToHidden();" Text="Button" />
</div>
</form>
</body>
</html>


This is a sample of a code behind which gets the HTML from the hidden field
and then you do with it as you want.



Partial Class TestGetHTML
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim txt As String
txt = Me.HiddenField1.Value

End Sub
End Class

Hope this helps
Lloyd Sheen
 
Back
Top