View Full Version : data entered into a form not coming out properly
HI there
Can anyone tell me is there a way to get a text box to accept text copied and pasted into it. without having to go through putting in the html if you want it to come out of a database the same way it went in.
Like the page I am submiting this into now. i press
return and it puts in the a carriage return.
Is there a script to do this for a asp page with a text box on it.
please help as to many a hour wasted hand coding text.
:mad: :confused:
Spudhead
10-01-2002, 03:49 PM
The way I get round this is firstly by escaping the text string before it goes into the database.
The when I'm pulling the values back out, I run the following on them:
(this is in JSCRIPT, but should be pretty easy to do in VBSCRIPT)
var myTextValue = myRecordSet.Fields("bigLumpOfText").value;
while(myTextValue.indexOf("%0D%0A")>-1){
myTextValue = myTextValue.replace("%0D%0A", "<br>");
}
Response.Write(unescape(myTextValue));
Any use?
whammy
10-02-2002, 01:28 AM
You can replace the database stuff when you are displaying it with things like:
mydatabasevariable = Replace(mydatabasevariable,vbCrlf,"<br />")
I'm not sure exactly what the problem is from your post, though... (since you didn't post any code!!!) although I would avoid using spudhead's solution (or using Server.HTMLEncode on a variable that's written to the database - you only want to do that when you are displaying a value!), as it can change the length of the entry and possibly cause a data truncation error.
Hi whammy
I have made a couple of online submital centres for press centres and news desk for sites.
The question i am asking is there any way to save the people using these having to put the html coding into the articles as they submit them so they come out of the database the same they way where submitted without having to type in <br> and <b>
But actually have the submital form accept the text as it is typed in.
The form i have to use to display this reply accepts that when i hit return to move the text to the next line without me having to tell it to do so. This means that i can copy and paste text into it and it looks the same way as when it is displayed as when i pasted it into the form.
At the moment when i copy and paste into the form that submits the info into the database it puts it into the database ok but then the page displays it as one huge line of text unless i go through the text after i have pasted it into the form and put in the html code to tell it where the carriage returns are and where the lists are.
There must be a easier way for this to done.
I have used access 2000 databases and SQL2000 databases depending on the size of the site and then asp to display them.
I was hoping there was some code i can stick either on the display pages or on the submital pages to add the code or for the display pages to read the information in the database and display it properly.
I hope this explains the problem more clearly?
:confused:
Alekz
10-02-2002, 12:09 PM
Hi Dean,
whammy gave You a way to replace ASCII line breaks with HTML ones. If Your formatting is text only - I mean no bold, center, etc - just tabs for text align, You could output Your text inside a <pre> tag.
But, if You need more advanced formatting as bold, italic, etc. I'm affraid there's no simple way to do this through a server side script, unless users are submitting valid HTML from Your form...
The other approach You can see in this forum - try to bold some text when writing and see what is actually submitted...
Alex
whammy
10-03-2002, 01:13 AM
This might be of interest to you - although it only works in IE.:
http://www.interactivetools.com/products/htmlarea/
:)
<%
Function cleanString(string_clean)
string_clean = Replace(string_clean, "<", "<") 'stops anything that could be a tag, like <table> which is mess up your page
string_clean = Replace(string_clean, ">", ">") ' stops anything that could be the end of a tag
string_clean = Replace(string_clean, "", " target=_blank >link</a>]")
string_clean = Replace(string_clean, "", " border=0>")
string_clean = Replace(string_clean, "", "<b>")
string_clean = Replace(string_clean, "", "</b>")
string_clean = Replace(string_clean, "", "<i>")
string_clean = Replace(string_clean, "", "</i>")
string_clean = Replace(string_clean, "", "<u>")
string_clean = Replace(string_clean, "", "</u>")
string_clean = Trim(string_clean) ' gets rid of extra white spaces
string_clean = Replace(string_clean, chr(13), "<br />") ' replaces carrage returns with <br />
cleanString = string_clean
End Function
%>
for any string you want to clean just use:
varName = cleanString(varName)
argh, code is all messed up thanks to vB_code
Go here for working code (http://chronicyouth.com/code.asp)
Hi Philip
Looking at the code you have put up but won't this will wipe out any tables or image source code that is put in.
some of the stuff put in has tables and the code for images so that the text can be seen to look like it is wrapping round the images.
I suppose it is a trade off either I use the forms the way they are and be able to format a page the using html or they copy and paste the writing in and clean it up and then have it come out looking the same but loose the ablility to use html coding for formatting.
As a possible comprimise to keep the best of both words.
Would it not be simpler to stick a row buttons down the side of the form like the submittle page for this forum does and actually make it easier for them to put the html coding in.
Like a button that you click and it adds the <BR> tag into the formand another button for <b> and another for </B> so that when they are inputting the information they simply have to go through it and click the appropriate button to put in the correct code. this also removes the chance of them sticking in incomplete code and stuffing up the formating of page completely.
I have looked at the source code for the reply page for this forum and smiley face has this code for the buttons:
<a href="javascript:smilie(':)')"><img src="images/smilies/smile.gif" alt="smile" border="0"></a>
This code inserts the following into the form " :) "
So this is the type of thing i am thinking of for the buttons.
Do you know the code for me to be able to make this happen.
Any Suggestions welcome as what ever i end up doing has to cater for all the different uses for the forms unless i do one type for just copying and pasting text into using the cleanstring you suggest and then the button type i have suggested for the forms that need to include html code for formating the layout of images with in the articles.
Any suggestion.
string_clean = Replace(string_clean, "<", "<") 'stops anything that could be a tag, like <table> which is mess up your page
string_clean = Replace(string_clean, ">", ">") ' stops anything that could be the end of a tag
this replaces the tags so they will show up on the page like <table> instead of actually becoming part of the html page and messing it up
string_clean = Replace(string_clean, "[ i ]", "</i>")
is my own code so you can code italics bold etc in to the page.
string_clean = Replace(string_clean, chr(13), "<br />") ' replaces carrage returns with <br />
charactor 13 is a carrage return. asp reads chr(13) and makes it a <br> into your database so it will become part of the html when taking out of the database displaying a return rather then <br>
if this doesn't help give me a example.
You can AIM me: phipxwork, or phipx
MSN: phipx@hotmail.com
If anything you just need:
function cleanString(string_clean)
string_clean = Replace(string_clean, chr(13), "<br />")
end function
this will do the carrage return only. but you page will be at the mercy of who posts. for if anyone puts in <tr> or leaves out a tag it will mess up your whole page. :p
whammy
10-04-2002, 01:59 AM
Not really... you can use this very useful function:
Server.HTMLEncode(string)
to disable input of HTML when you display a string... and ONLY when you display it, lest you mess something else up! :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.