Forum Moderators: coopster

Message Too Old, No Replies

Retrieving POST data

how to get the whole field with spaces

         

d40sithui

12:21 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



hey guys. kidna noob question here.

i have a form as such
<input type=text name=address size=75>

if someone enters like:
"my house here in MD"

using the $_POST['address'] i can only get the first part of the string "my". there must be a way to get the rest of it. if so, please advise. thanks.

-khanh

Habtom

12:25 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<input type="text" name="address" size="75">

"my house here in MD"

$_POST['address'] should give you the whole thing.

Note: I have added the double quotes, may be their absense is causing this.

Habtom

d40sithui

12:46 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



negative on that. if quotes were the problem, i wouldnt get anything back. but i get the first part of the string back, which is "my"
any other thoughts?

coopster

12:49 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How are you retrieving and using the input, $_POST['address']?

d40sithui

1:00 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



yea. very simple.

the form:
<input type="text" name"address" size=75>

php form handler:
$address = $_POST['address'];
echo $address;

Habtom

1:02 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<input type="text" name"address" size=75>

if you just copied that, the name "=" sign is missing.

d40sithui

1:07 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



oh yeah retyped it sory, "=" sign is there

d40sithui

1:10 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



ok thats odd, i just tried te same thing ona diff server. works fine. hmm...maybe php.ini is culprit?

coopster

1:11 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you disabled javascript in the browser to make sure there isn't any client-side code modifying the contents before they get returned to you?

d40sithui

1:22 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



ok guys, i found the problem!
it was just me being retarded.
the post data was being filtered by php function and somehow it trimmed everything after the first space. fixing that right now

-khanh

coopster

1:24 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Figured that was likely the culprit when I seen you post this ...

php form handler:

... but thought it wise to check the client side first, then move on to tracking it's path on the server side. Glad you got it sorted, nice work.

d40sithui

1:36 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



hey well actually i just found out that it didnt trim at all. the reason it only printed everything before the first space was because of this:

what i had before -- // prints only first word
<input type="text" name="address" size=75 value= <? echo address;?>
>

after (notice the quotation) //prints all
<input type="text" name="address" size=75 value='<? echo address;?>'
>

silly me =)

coopster

1:51 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



what i had before -- // prints only first word
<input type="text" name="address" size=75 value= <? echo address;?>
>

Actually this is not what you stated, you said you were just echoing the address as ...

php form handler:
$address = $_POST['address'];
echo $address;

... which is quite different. When you write code out embedded in the HMTL you have to handle it differently. And, as you have figured out, "View Source" will often save you many headaches. You need to take your output and make it browser safe as follows ...

after (notice the quotation) //prints all
<input type="text" name="address" size=75 value='<? echo htmlentities [php.net](address);?>'
>

d40sithui

2:05 pm on Jul 12, 2007 (gmt 0)

10+ Year Member



ah so my details were off before. but i really didnt figure that would be the problem. turns out it was. thanks for the tip coop.

coopster

2:10 pm on Jul 12, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It's all in the details ;)

You are very welcome.