psoting hidden string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Gavski
Forum Newbie
Posts: 19
Joined: Thu May 16, 2002 2:30 pm
Location: UK

psoting hidden string

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
User avatar
Gavski
Forum Newbie
Posts: 19
Joined: Thu May 16, 2002 2:30 pm
Location: UK

Gets it

Post 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.
User avatar
Gavski
Forum Newbie
Posts: 19
Joined: Thu May 16, 2002 2:30 pm
Location: UK

Post by Gavski »

Thanks to Jason also,

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