Page 1 of 1

psoting hidden string

Posted: Sun May 19, 2002 5:45 am
by Gavski
Problem:- I need to pass text from one page to another using hidden input like this:-

(page1) <textarea name=message>...form...post...etc,

(page2)<?php echo $message;
echo "<input type=hidden value=$message>"; ?>

(page3) <?php echo $message; ?>

This works fine until I use an apostrophe ' the mesage is displayed fine in page2 but page3 only displays the part of the textarea before the apostrophe '.

I have tried addslashes()/stripslashes() but this makes no difference

Help appreciated

Thanks

Posted: Sun May 19, 2002 6:38 am
by volka
probably because the HTML-source as seen by the browser look like
<input type=hidden value='it's all over now'>
The parser takes value='it'
write <input type="hidden" value="it's all over now">
and value will be "it's all over now"
but the problem starts all over again if $message contains "
addslashes is not the proper function to escape characters in an input-field
use urlencode() and urldecode() instead

Posted: Sun May 19, 2002 9:00 am
by jason
For stuff like this, I would recommend using Sessions to store the values. You could easily put all the values into an array, seralize the array, and store it in a session. Once you need the data again, unserialize it, and move on.

Gets it

Posted: Sun May 19, 2002 9:02 am
by Gavski
Hi Volka,

I'm quite new to this and my lack of code knowledge causes me problems
but it's great when things work out, this was very basic but gave me much hair pulling.

urlencode()/decode() does the business a treat!! so thanks v much for your help.

As I get more experienced I will make a point of trying to answer other peoples questions, I know how much it can help.

Thanks again.

Posted: Sun May 19, 2002 9:06 am
by Gavski
Thanks to Jason also,

I will look into array sessions, it will keep me off the streets.