Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

maintaining state for a multipage process

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

maintaining state for a multipage process

Postby azw » Fri Oct 11, 2002 9:32 pm

I'm developing a site that has several PHP features. One of them allows a sender to mail an e-card to a friend. I have done a lot of input testing to be sure the user inputs are clean and safe. At each step, I give the user the opportunity to go back and revise their inputs, or to start over.

Okay, so on the first page I take their inputs, approve or edit them for security, and then send them to a preview page. Because I need to manipulate the data inputs first on the input page, I maintain state with their data by creating a session. I haven't figured out a way to send the data by POST because I test it with PHP after they click on SUBMIT. That processing often changes the data, so their inputs are no longer used.

If the user wants to return to the input page from the preview page, the browser (IE) tells them that they have to press "refresh" to resubmit the data get. That's really bad for usability. It makes me look like I messed up!

How do I pass the data between pages more smoothly?

I used <input type="button" value="Edit" onClick="history.go(-1);>, and I've also tried it with just the URL of the input page. Is there a better way to go back one page?

Thanks.
azw
New php-forum User
New php-forum User
 
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm

Postby azw » Fri Oct 11, 2002 10:07 pm

Update:

I now see that the refresh message only appears when the user has been forced by my script to change the inputs because of errors. The email address entered might not be valid, or there might be unallowed characters in the input.

If there were no problems on the input page, the user will not get the refresh message when they're on the preview page and try to return to the input page via my link.

The link I listed above is missing a quote. It should read:
<input type="button" value="Edit" onClick="history.go(-1);">
azw
New php-forum User
New php-forum User
 
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm

Postby DoppyNL » Sat Oct 12, 2002 12:21 am

when sending the user back to the form you can also give a normal link (a href) to the form page, then the browser wil request that file again from the server.
In that script you can insert the allready submitted data in the form wich you are keeping in session variables. When the user views the form it will see everything he added (and everything you possible changed on the way).

Greetz Daan
DoppyNL
 

Postby azw » Sat Oct 12, 2002 7:01 am

Hi, thanks for responding!

I get this message:
------------
Warning: Page has Expired The page you requested was created using information you submitted in a form. This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you.

To resubmit your information and view this Web page, click the Refresh button.
------------

Yes, I am using $_SESSION[] variables for the values in the form. The data will appear just fine as long as I don't have any errors on the input page. But if the input page catches an error, and I correct the entry error, then after I go to the preview page and try to go back to the entry page to edit, I get the message above. If I didn't make any corrections and didn't have any errors, then I can just see the input page without the message about refreshing the page's data. Weird.

I guess there could be something in the correction process that doesn't update the data in the $_SESSION variables.

All along in my script I use lines like:
$_SESSION['msg']=replaceChars($_POST['msg']); // runs a function to clean up the input
to put the data into the $_SESSION vars as it is changed. Do I have to do anything else to be sure it's updated?
azw
New php-forum User
New php-forum User
 
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm

Postby azw » Sat Oct 12, 2002 8:07 am

Here's another detail that may be telling us something.

If the browser requires a refresh of the data, the data that shows up in the refreshed input page is the OLD uncorrected data. The data had been displayed correctly in the preview page (the one you go to after the input page), but reverts to the old data when you refresh the input page.
azw
New php-forum User
New php-forum User
 
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm

Postby azw » Sat Oct 12, 2002 9:06 am

Here's another clue, and maybe the main issue:
I have success if I give myself another route back to the input page, via a plain link:
<a href="artCard5.php">edit</a>
That seems to work.

I would like to keep the button. Bu then it doesn't work at all (nothing happens when I click the button). Is there something wrong with this code, or is it simply impossible to wrap a form's input element in an anchor?
<a href="artCard5.php"><input type="button" value="Edit"></a>
azw
New php-forum User
New php-forum User
 
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm

Postby azw » Sat Oct 12, 2002 9:37 am

Okay, so it seems to be a problem with using history in the input element.

Am I correct in assuming that php isn't able to add the session info to the history ref in the following?
<input type="button" value="Edit" onClick="history.go(-1);">


I haven't been able to get this following idea to work.
<a href="artCard5.php"><input type="button" value="Edit"></a>
Is there a way to wrap a button with an anchor?


Or is there a better way to create an href link with an input button?


I"ve had success by puttin this in the form:
<input type="button" value="Edit" onClick="redirect('artCard5.php');">

and then send to this function:

<script type="text/javascript" language="javascript">
function redirect(loca){
window.location.href=loca;
// window.location.href="http://www.zollerwagner.com/realistPtg/artCard5.php";
}
</script>

That seems terribly heavy-duty given the simplicity of what I'm trying to do. Any better ideas?
azw
New php-forum User
New php-forum User
 
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm

Postby Jay » Sat Oct 12, 2002 2:13 pm

What an incredible monologue, I've only ever seen one other like it :D

Anyway, I haven't read through it all because it seems that the basic crux of your problem is the refreshing thing, so I'm going to explain why that happens!

When you submit a form, the resulting page is a specially engineered page designed just for you on the basis of what you submitted. It's not a standard page. Which is why when you leave that page and want to return to it, the variables must be submitted again so you get the same page back.

The easiest way about the whole thing is to use a session to keep track of all the data and how far the user has gone. Use normal hyperlinks to backtrack so a new page is called, but use the session to work out whether the data has already been submitted, and if so fill in the gaps for the user. Just do that at every stage and you will be sorted!

To use a button as a link do this:
<input type=button value='This is the button text' onClick="document.location='thepage.php'">
Jay
 

Postby azw » Sat Oct 12, 2002 6:10 pm

Makes sense. Do you think that I can't use the history(-1) technique with sessions, because that doesn't allow PHP to add its session id to the url?

At least I have it working now.
Thanks!
azw
New php-forum User
New php-forum User
 
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm

Postby Jay » Sun Oct 13, 2002 1:07 am

Don't use history(-1), that's javascript and has nothing to do with PHP. The problem with using the history command is it's just the same as pressing the back button (because it goes back to the previous page, whatever that was). Because the previous page was the result of submitting a form, IE will ask for you to submit the data again to make sure it gets the same page. If you use the normal link to the page, it'll just call a fresh copy and you can use the sessions to manipulate it so that it's already filled in!
Jay
 

Postby azw » Sun Oct 13, 2002 9:50 am

Now that I think about it, I can see that history object IS javascript. Too bad that wasn't obvious to me at first!
Thanks!
azw
New php-forum User
New php-forum User
 
Posts: 41
Joined: Fri Oct 11, 2002 9:13 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.