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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML FORM, POST method, problems with spaces in fields 1

Status
Not open for further replies.

jaredc

Programmer
Jun 28, 2002
43
GB
Hi I've got a problem which I do have a work around for, but I was wondering whether anyone has any better ideas.

The basic scenario is I have a number of text INPUT fields on a web page for users to enter data on. The INPUT fields are contained within an HTML FORM on the page and I'm passing the values to the next page using the POST method.

The problem arises when I try to view the contents of the fields in the next page and everything behind a space (contained in the INPUT fields) seems to have disappeared, e.g.

Original text in field = "My input text"
value after passing to next page = "My"

I don't really understand why this is happening and I've previously got round this problem by submitting the FORM to the same page and replacing the space characters with some other character before submitting the FORM to the next page. Ideally I don't really want to have to to this and wondered whether anyone could suggest another method or shed any light on why this is happening.

Hope this makes sense and thanks in advance for any thoughts or advice

Mike
 
Hi sjravee

I'm initially writing my text input tags from within ASP as follows;
Code:
Response.Write &quot;<form NAME=frmNameAddress METHOD=POST ACTION=&quot; & chr(34) & &quot;NextPage.asp?Action=EnterDetails&quot; & chr(34) & &quot;>&quot;
Response.Write &quot;<input TABINDEX=1 VALUE=&quot; & Chr(34) & Request.Item(&quot;txtTitle&quot;) & Chr(34) & &quot; name=txtTitle style=&quot; & chr(34) & &quot;HEIGHT: 22px; WIDTH: 300px&quot; & chr(34) & &quot;>&quot;
Response.Write &quot;</form>&quot;
(without the asp bits:)
Code:
<form NAME=frmNameAddress METHOD=POST ACTION=&quot;SecOrder_Pay.asp?Action=EnterDetails&quot;>
<input TABINDEX=1 name=txtTitle style=&quot;HEIGHT: 22px; WIDTH: 300px&quot;>
</form>
Then on the next page extracting the items by using
Code:
strTitle = Request.Item(&quot;txtTitle&quot;)
Response.write strTitle
Is there possibly something I could specifiy on the INPUT tags themselves?
 
you are missing single quotes around your value in the input field, this is why the text is being truncated.
change it to :

Response.Write &quot;<input TABINDEX=1 VALUE='&quot; & Request.Item(&quot;txtTitle&quot;) & &quot;' name='txtTitle' style='HEIGHT: 22px; WIDTH: 300px'>&quot;

not sure what you were trying to acheive with the Chr(34) so i removed them
 
Thanks sjarvee, adding in the single quotes round the INPUT tag name seems to have done the trick initially (I've only had a chance to very quickly test this, as I'm passing the values through a number of pages, very tedious to keep track of!) but I'm still having some problems. I'll try to work through these myself but may have to post again later.

Thanks once again and by the way, I use the &quot;& chr(34) &&quot; to represent the &quot; (double quote) character within the output strings on the Response.write command in VBScript. e.g.:
Code:
response.write &quot;<IMG SRC=&quot;/images/pic.gif&quot;>&quot;
would result in an error, which I sort out by:
Code:
response.write &quot;<IMG SRC &quot; & chr(34) & &quot;/images/pic.gif&quot; & chr(34) & &quot;>&quot;
I hope that made at least some sense!
 
simpler method would be to write it as:

response.write &quot;<IMG SRC=&quot;&quot;/images/pic.gif&quot;&quot;>&quot;
 
Thanks for the &quot;&quot; advice sjarvee, i think you must have just saved me many hours of typing in the future!

Unfortunately, I'm still having difficulties loosing spaces, my debugging seems to suggest I am loosing text after spaces when I'm using hidden input fields on subsequent pages. Here's the code I've got:
Code:
Response.Write &quot;<form NAME=frmOrder METHOD=POST ACTION=&quot;&quot;NextPage.asp?Action=CheckDetails&quot;&quot;>&quot;

Response.Write &quot;<INPUT TYPE=HIDDEN NAME='txtTitle' VALUE=&quot; & Request.Item(&quot;txtTitle&quot;) & &quot;>&quot;

Response.Write &quot;</form>&quot;
I'm pretty certain that the value in &quot;txtTitle&quot; is correct, but when I try to view the txtTitle in the next page I've lost everything after the spaces. I've included the single quotes around the name of the input field as suggested earlier but still seem to be getting this problem. The fact that I'm using the name txtTitle for two differnt things wouldn't affect it would it?

Thanks in advance for any advice
 
Its the same problem with the value. Do it 1 of the 2 following ways
eg

Response.Write &quot;<INPUT TYPE=&quot;&quot;HIDDEN&quot;&quot; NAME=&quot;&quot;txtTitle&quot;&quot; VALUE=&quot;&quot;&quot; & Request.Item(&quot;txtTitle&quot;) & &quot;&quot;&quot;>&quot;

or

Response.Write &quot;<INPUT TYPE='HIDDEN' NAME='txtTitle' VALUE='&quot; & Request.Item(&quot;txtTitle&quot;) & &quot;'>&quot;

with the first method you have to watch out for double quotes in the Request.Item(&quot;txtTitle&quot;) value, this will break the VALUE string and give you the same problem you are having. Same applies with single quotes for the last method

If you are reading data from a form &quot;Post&quot; method use Request.Form to return you the value of form elements, so in your case request.form(&quot;txtTitle&quot;). If you are using a Form &quot;Get&quot; method use Request.Querystring instead. I wouldnt use request.item.

Anyway hope this helps



 
Thanks very much sjarvee, I've now got the full process working. I used the first method (three double quotes surrounding Request.Form(&quot;txtTitle&quot;)) rather than the second method of double quote then single quote as I found that this &quot;commented out&quot; the remainder of the line of code - if you know what I mean. (I do find all these quotation marks can get very confusing!)

Is there any particular reason for not using Request.Item with the POST method? I was also under the impression that using the GET method is not recommended, is this the case as far as you know?

Thanks once again for your help and advice - it has saved me a vast amount of additional coding and the associated headache!
 
the thing with request.item is that its only the person that wrote the code that would immediately know that a form element is being read as opposed to a querystring parameter. I'm so used to debugging other peoples work that I always hope that they specify these types of things as it cuts down on support time and costs. I just find it a lot easier to debug and understand whats going on when you specify Form or querystring, thats me though. You have not done anything wrong, im just being a picky bastard :). You could just write request(&quot;txtTitle&quot;) if you really wanted to.

When dealing with text fields it is best to use a form post method. Using the Get method appends the form data onto the end of the form action. If one of these form values was very long it may end up exceeding the maximum allowed length for a url. Thats one problem, the other is that people see loads of gubbins on the url and think i know what, ill fiddle with that url and what happens ie. change somepage.asp?Num=123&Letter=ABC to somepage.asp?Num=ABC&Letter=123, i do it all the time!

Form Get methods are usually used by search engines, the Get method puts the form elements name and value into the querystring, this is great if you want to save you search criteria (simply by saving the url or adding to favourites) but not so great if you are submitting vast amounts of data.
 
Thanks very much for those explanations sjarvee. Points taken in the first paragraph - I too have been on the receiving end of trying to debug existing/other poeples code, it can be rather time consuming... I'm always happy to take constructive criticsm also, it is my aim to strive for perfection in the world of IT!
The POST vs. GET method info I kind of knew, I've also had problems shifting data between web servers when trying to use the GET method which were cured again by using POST.
Thanks very much once again
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top