Forum Moderators: open

Message Too Old, No Replies

Returning textarea in URL

         

traeanthony

3:59 am on Aug 18, 2005 (gmt 0)

10+ Year Member



I'm making a site for a local company, the thing is, we have a form on the site that allows people to enter information in various text boxes and in a text area. The form is then sent to an asp script that saves the inputed data to a text file, and then returns to the form page. The data that was entered is then displayed in the form again, like it's supposed to, except for the text area when it contains line returns. How to I get this to appear correctly in the text area when there are line returns?

emsaw

6:02 am on Aug 18, 2005 (gmt 0)

10+ Year Member



traeanthony,

Is the data store that the information being sent into retaining the line breaks? If you are passing things around in the querystring, the URL encoded value for the new line, a carriage-return line-feed, it is %0D%0A
Make sure that your textarea text is encoded correctly when it's on it's way out to the script and you should be good.

I mocked up an example in .Net of passing URL encoded information into a textbox if you would like to see it.

Sorry, I don't mean to either talk under or over you, but I don't know your level of experience.. just offering my 2 cents :)

-Mark

traeanthony

6:45 am on Aug 18, 2005 (gmt 0)

10+ Year Member



Mark,
I'll admit, I'm a begginer so any info helps. Thank you so much for your response. I would love to see your example. I don't know if it will answer this question but, how do I format the carage returns in the text area as it's being sent off?

-Trae

mrMister

11:50 am on Aug 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



post your code and we'll have a look, not much we can do without a full understanding of what you're doing

traeanthony

4:28 pm on Aug 18, 2005 (gmt 0)

10+ Year Member



Here's the first page with the form and the textarea (please note, we're saving text files as .vtx files so a program we have can read it.)(this would be saved as "index.asp"):
---------------------------------

<html>
<body>
<font face="arial">
<!--Creats and Saves File-->
<form action="save.asp">
<table border="1" cellpadding="0" cellspacing="0" width="550" style="border-collapse: collapse" bordercolor="#000000">
<tr>
<td>

<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<% if request("filename") > 0 then %>
<td colspan="2" bgcolor="cfcfcf">&nbsp
THIS IS THE FILE THAT YOU ARE CURRENTLY WORKING ON:
<font color="red">
<% response.write(request("directory") & request("filename") & ".vtx") %>&nbsp
</td>
</tr>
<%else%>
<tr>
<td colspan="2" bgcolor="cfcfcf">&nbsp
You do not have a file open.
</td>
</tr>
<%end if%>
</table>

</td></tr>
<tr><td>

<table cellpadding="0" cellspacing="0" width="100%">
<!--<tr>
<td><font face="arial">File Name:</td>
<td><input type="text" name="filename" value="<%=request("filename") %>" size="20">.vtx</td>
</tr>
<tr>
<td><font face="arial">Page Number:</td>
<td><input type="text" name="pagenum" size="20"></td>
</tr>-->
<tr>
<td><font face="arial">Coding:</td>
<td><textarea rows=20 cols=50 name="coding"><%=request("coding") %></textarea></td>
</tr>
<tr>
<td><font face="arial">Directory/File Name:</td>
<td><input type="text" name="directory" value="e:\wwwroot\testfolder\" size="20">&nbsp\
<input type="text" name="filename" value="<%=request("filename") %>" size="20">&nbsp.vtx</td>
</tr>
<tr>
<td colspan="2" align="middle"><input type="submit" name="Submit" value="Save"></form></td>
</tr>
<% if request("err") = filename then %>
<tr>
<td bgcolor="red" colspan="2"><b><center>YOU MUST ENTER A VALID FILE NAME!</b></td>
</tr>

<% else %>
<tr>
<td height="1"></td>
</tr>
<%end if%>
</table>

</td></tr>
<!--<tr><td>

<!--Opens File

<form action="opendoc.asp">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>Directory and filename:</td>
<td><input type="text" name="directory" value="e:\wwwroot\testfolder\" size="20"><input type="text" name="filename" size="20">.vtx</td>
</tr>
<tr>
<td colspan="2" align="middle"><input type="submit" name="Submit" value="Open"></form></td>
</tr>
</table>

</td></tr>-->
<tr><td>

<table>
<tr>
<td>
Full URL String:<br><font size="1">
[domain.com...] color="blue">?filename=<font color="red"><%=response.write(request("filename"))%><font color="blue">&coding=<font color="red"><%=response.write(request("coding"))%><font color="blue">&directory=<font color="red"><%=response.write(request("directory"))%><font color="000000">

<!--response.write("http://www.domain.com/testfolder/?" & "filename=" & request("filename") & "&coding=" & request("coding") & "&directory=" & request("directory"))-->

</td>
</tr>
</table>

</td></tr></table>

</body>
</html>

---------------------
Here's the asp page that saves the vtx document (From this page it should redirect to the previous page, displaying all entered data in the fields exactly how they were entered.) (this would be saved as "save.asp"):
-----------------

<% If len(request("filename"))<1 then
response.redirect ("/testfolder/?err=filename" & "&filename=" & request("filename") & "&coding=" & request("coding") & "&directory=" & request("directory"))
End if

If len(request("coding"))<1 then
'response.write "/testfolder/?err=coding"
response.redirect ("/testfolder/?err=coding" & "filename=" & request("filename") & "&coding=" & request("coding") & "&directory=" & request("directory"))

End if

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(request("directory") & request("filename") & ".vtx", ForWriting, True)
f.Write request("coding")

'response.write("/testfolder/?" & "filename=" & request("filename") & "&coding=" & request("coding") & "&directory=" & request("directory"))
response.redirect("/testfolder/?" & "filename=" & request("filename") & "&coding=" & request("coding") & "&directory=" & request("directory"))
%>

------------------------
So far, I return all data to the proper fields, except the textarea. The text area will display all entered text, untill it gets to a carriage return, then from there on, nothing is displayed.

emsaw

12:30 am on Aug 19, 2005 (gmt 0)

10+ Year Member



traeanthony,

So it looks like in any place you are referencing the values from the 'coding' textarea, you will want to URLEncode() the value.
so something along the lines of


TextAreaValue = URLEncode(Request.Form["coding"])

if you put in:
Html
That
Makes
Lines

the output of URLEncode should produce:
Html%0D%0AThat%0D%0AMakes%0D%0ALines

emsaw

12:53 am on Aug 19, 2005 (gmt 0)

10+ Year Member



I had a better look at it and all you would need to do is as above put enclose the 'coding' field with URLEncode() in save.asp

so for example, one line of that file is:


response.redirect("/testfolder/?" & "filename=" & request("filename") & "&coding=" & request("coding")& "&directory=" & request("directory"))

just change it to:

response.redirect("/testfolder/?" & "filename=" & request("filename") & "&coding=" & URLEncode(request("coding")) & "&directory=" & request("directory"))

-- this should do what you want.
-Mark

traeanthony

3:20 am on Aug 19, 2005 (gmt 0)

10+ Year Member


Okay, i'm having some problems.

this is the code for the index page with the text area

<textarea rows=20 cols=50 name="coding" style="border: 1px solid #000000"><%TextAreaValue = URLEncode(Request.Form("coding"))%></textarea>

here's one of the lines on the save.asp page

response.redirect("/docutech/?" & "filename=" & request("filename") & "&coding=" & URLEncode(rrequest("coding")) & "&directory=" & request("directory") & "&type=" & request("type"))

It's returning to the previous page with the correct url string like it should be doing, but i'm getting a VB Run Time error. The weird thing is, it loads the text area and it places the error in the text area exactly like this (code and all):

<font face="Arial" size=2>
<p>Microsoft VBScript runtime </font> <font face="Arial" size=2>error '800a000d'</font>
<p>
<font face="Arial" size=2>Type mismatch: 'URLEncode'</font>
<p>
<font face="Arial" size=2>/docutech/index.asp</font><font face="Arial" size=2>, line 43</font>

What am i doing wrong?

emsaw

6:33 am on Aug 19, 2005 (gmt 0)

10+ Year Member



traeanthony,

Sorry, should have been more clear, just leave the original page with the textarea alone, so:

<textarea rows=20 cols=50 name="coding" style="border: 1px solid #000000"><%TextAreaValue = URLEncode(Request.Form("coding"))%></textarea>

can still be left as:
<textarea rows=20 cols=50 name="coding" style="border: 1px solid #000000"><%Request("coding")%></textarea>

and I'm not sure if that's just a typo in your save.asp , but you have a double 'r' for the 'request' inside the URLEncode .
Perhaps after removing the extra 'r' that will fix it?

Mark

traeanthony

2:16 pm on Aug 19, 2005 (gmt 0)

10+ Year Member


Hey, thanks for pointing out the double r. unfrotunatly, it didn't work though. instead of displaying any error, it now just shows the default HTTP 500 interenal server error page.

this is the complete codeing for the index.asp page:
----------------------------------------

<html>

<body bgcolor="ababab">
<font face="arial">
<!--Creats and Saves File-->
<form action="save.asp">
<table bgcolor="ffffff" border="1" cellpadding="0" cellspacing="0" width="550" style="border-collapse: collapse" bordercolor="#000000">
<tr>
<td bgcolor="cfcfcf">

<table cellpadding="0" cellspacing="0" height="100%" width="100%">
<tr>
<% if len(request("filename")) < 1 then %>
<td colspan="2" bgcolor="cfcfcf">&nbsp
You do not have a file open.
</td>
</tr>
<%else%>
<tr>
<td colspan="2" bgcolor="cfcfcf">&nbsp
You currently have the following file open:
<font color="red">
&nbsp<% response.write(request("directory") & request("filename") & ".vtx") %>&nbsp
</td>
</tr>
<%end if%>
</table>

</td></tr>
<tr><td>

<table cellpadding="0" width="100%" style="border-collapse: collapse" border="0">
<!--<tr>
<td><font face="arial">File Name:</td>
<td><input type="text" name="filename" value="<%=request("filename") %>" size="20">.vtx</td>
</tr>
<tr>
<td><font face="arial">Page Number:</td>
<td><input type="text" name="pagenum" size="20"></td>
</tr>-->
<tr>
<td><font face="arial">Coding:</td>
<td><br><textarea rows=20 cols=50 name="coding" style="border: 1px solid #000000"><%=Request("coding")%></textarea>&nbsp</td>
</tr>
<tr>
<td><font face="arial">Directory/File Name:</td>
<td>
<input type="text" name="directory" value="e:\wwwroot\testfolder\" size="20" style="border: 1px solid #000000">&nbsp
<input type="text" name="filename" value="<%=request("filename") %>" size="20" style="border: 1px solid #000000">&nbsp.vtx</td>
</tr>
<tr>
<td colspan="2" align="middle"><input type="submit" name="Submit" value="Save"></form></td>
</tr>
</table>

</td></tr>

<!--ERROR RESPONSES-->
<% if request("err") = "filename" then %>
<tr>
<td bgcolor="red" colspan="2"><b><center><font color="ffffff">File name must be at least 7 characters.</b></td>
</tr>
<%end if%>
<% if request("err") = "filenamebig" then %>
<tr>
<td bgcolor="red" colspan="2"><b><center><font color="ffffff">File name must be 7 to 8 characters.</b></td>
</tr>
<%end if%>
<% if request("err") = "coding" then %>
<tr>
<td bgcolor="red" colspan="2"><b><center><font color="ffffff">Your coding field is empty.</b></td>
</tr>
<%end if%>
<% if request("err") = "directory" then %>
<tr>
<td bgcolor="red" colspan="2"><b><center><font color="ffffff">Please enter a valid directory.</b></td>
</tr>
<%end if%>

<!--<tr><td>

Open File

<form action="opendoc.asp">
<table cellpadding="0" cellspacing="0" border="0" width="100%" >
<tr>
<td>Directory and filename:</td>
<td><input type="text" name="directory" value="e:\wwwroot\testfolder\" size="20"><input type="text" name="filename" size="20">.vtx</td>
</tr>
<tr>
<td colspan="2" align="middle"><input type="submit" name="Submit" value="Open"></form></td>
</tr>
</table>

</td></tr>-->
<tr><td>

<table width="100%" cellpadding="0" cellspacing="0" bgcolor="cfcfcf">
<tr>
<td>
Full URL String:<br><font size="1">
http://www.domain.com/testfolder/<b><font color="blue">?filename=<font color="red"><%=response.write(request("filename"))%><font color="blue">&coding=<font color="red"><%=response.write(request("coding"))%><font color="blue">&directory=<font color="red"><%=response.write(request("directory"))%><font color="000000">
<br>
Full URL String sent to save.asp:<br> <font size="1" color="red">
<% response.write("/testfolder/?" & "filename=" & request("filename") & "&coding=" & request("coding") & "&directory=" & request("directory"))%>

<!--response.write("/testfolder/?" & "filename=" & request("filename") & "&coding=" & request("coding") & "&directory=" & request("directory"))-->

</td>
</tr>
</table>

</td></tr></table>

</body>
</html>

---------------------------------------

and here is the coding for the save.asp page:

----------------------------------------

<% if len(request("filename")) < 7 then
response.redirect ("/testfolder/?err=filename" & "&coding=" & URLEncode(request("coding")) & "&directory=" & request("directory") & "&type=" & request("type"))
End if

If len(request("filename")) > 8 then
response.redirect ("/testfolder/?err=filenamebig" & "&coding=" & URLEncode(request("coding")) & "&filename=" & request("filename") & "&directory=" & request("directory") & "&type=" & request("type"))
End if

If len(request("coding")) < 1 then
response.redirect ("/testfolder/?err=coding" & "&filename=" & request("filename") & "&directory=" & request("directory") & "&type=" & request("type"))
End if

If len(request("directory")) < 1 then
response.redirect ("/testfolder/?err=directory" & "&filename=" & request("filename") & "&coding=" & URLEncode(request("coding")) & "&type=" & request("type"))
End if

Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(request("directory") & request("filename") & ".vtx", ForWriting, True)
f.Write request("coding")

'response.write("/testfolder/?" & "filename=" & request("filename") & "&coding=" & URLEncode(request("coding")) & "&directory=" & request("directory") & "&type=" & request("type"))
response.redirect("/testfolder/?" & "filename=" & request("filename") & "&coding=" & URLEncode(request("coding")) & "&directory=" & request("directory") & "&type=" & request("type"))
%>

emsaw

5:25 pm on Aug 19, 2005 (gmt 0)

10+ Year Member



try using a 'Server.' in front of the URLEncode call.
so something like:
Server.UrlEncode(Request{"coding"})
(I just tried it on my local machine and it works)
-Mark

traeanthony

7:24 pm on Aug 19, 2005 (gmt 0)

10+ Year Member



YOU ARE A GENIOUS! It's works flaulessly. Thank you so much. You don't know how much I appreciate it!