Passing a string from one page to another.

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
Cosarin
Forum Newbie
Posts: 5
Joined: Thu May 25, 2006 3:22 pm

Passing a string from one page to another.

Post by Cosarin »

Hi. I hope someone can help.

This is propably a no brainer.................


I am trying to create a multipage form......ie............first page has first 6 questions and click to continue. Second page has more questions, and so on until you reach page five which shows summary of answers then allows a submit button to post all answers to database.

The database parts I have no problem with, but the passing between pages is giving me grief.

For one has the first 6 form items in them, I post these using the standard post method to a new php, which then retrieves these variables. Within the form on the second page I add hidden form fields representing the asnwers for page 1 and set the values as the retrieved variables.

The problem I am having is that when I get to the final page, I am again retrieving the variables, but for some reason when I try and echo the values, if a vairable contains more than one word, I still only get the first word in the string.

Why is this?
How can I stop this?

Thanks in advance.

Cosarin
jonra
Forum Newbie
Posts: 22
Joined: Thu May 25, 2006 9:35 am
Location: Iowa
Contact:

Post by jonra »

Are you doing any cleaning of the data at all from page to page? I don't remember a time where I was passing lots of string data as a hidden field, but I tested it and it's all coming out clean for me once submitted.
Cosarin
Forum Newbie
Posts: 5
Joined: Thu May 25, 2006 3:22 pm

Post by Cosarin »

Thanks for the reply.

The following is what I am doing between pages in the simplified manner.


Page 1

Code: Select all

<textarea name=message cols=100 rows=8 id=message>
Then Posted using From method POST to page 2

Page 2

Code: Select all

@$message = ($_POST['message']);
And then inserting this value into a new hidden form field also called message,

Code: Select all

<input name=message type=hidden id=message value=$message>
I am then once again posting this to page 3 in the same manner with POST

And So on and So until I reach page 5 when instead of placing the value into a hidden field I echo the value

Code: Select all

echo "$message";
Obviously all code is within php tags in all pages.

But if I enter the string "Hello My Name Is Colin" into the textbox on page one. After I echo it on Page 5 all I get is "Hello"

I hope this helps you help me.

And thanks again

Cosarin
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. use quotes around your tag attribute values
  2. use sessions to pass data that shouldn't be manipulated by the user instead of hidden fields.
jonra
Forum Newbie
Posts: 22
Joined: Thu May 25, 2006 9:35 am
Location: Iowa
Contact:

Post by jonra »

Hmm, I'm confused. If you're using the same hidden field names and the variable $message in PHP to grab the values, aren't you overwriting the values after each submit?

Is it possible maybe to build a 'temp' table in your DB that can hold those temporary values for each session? So as each 'next' button is clicked, you grab all form values, put them as an insert into the temp table, and at the end of the application query the entire temp table - do the math - print the results - and kill the values in the table?

edit: Actually, after reading feyd's post, maybe I'd go with sessions also. Get all the values somewhere as a global storage for your application, and run through those values on the last page of the app. I don't know... Hidden fields just don't seem the best way to handle this IMO.
Cosarin
Forum Newbie
Posts: 5
Joined: Thu May 25, 2006 3:22 pm

Post by Cosarin »

Thanks both.

I am very much a newbie to php, and I have thought about the post each page to a temp DB first, and then finalise all the data at the end, but as feyd has mentioned sessions seems obvious now I think of it. I have used sessions before when creating a form verification script, so I shall give that a try.

However thanks jonra for your suggestions.

Cosarin

I shall let you know how I get on!
User avatar
xpgeek
Forum Contributor
Posts: 146
Joined: Mon May 22, 2006 1:45 am
Location: Kyiv, Ukraine
Contact:

Re: Passing a string from one page to another.

Post by xpgeek »

Cosarin wrote:skip
Sorry for Englis. I try.

1)Use tables to store tmp data.
2)Use sessions to store tmp data.
3)Use tmp files ;-) - it's like session or database variant.
3)Don't use hidden fields if you don't want check it all time when user submit form.

I prefer the database variant but sometimes sessions is prefered.
Post Reply