Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
Going back with multiple submits to the same page
Old
  (#1)
Otto Wyss
Guest
 
Posts: n/a
Default Going back with multiple submits to the same page - 05-14-2007, 03:34 AM

When values are entered on one of my page I submit the result back to
the same page (form action=same_page). Unfortunately each submit adds an
entry into the history, so history back doesn't work in a single step.
Yet if the count of submits were known I could use goto(n). What's the
best way to get this count? PHP or Javascript?

O. Wyss
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: [PHP] Going back with multiple submits to the same page
Old
  (#2)
Carl Pearson
Guest
 
Posts: n/a
Default Re: [PHP] Going back with multiple submits to the same page - 05-14-2007, 03:34 AM

Paul Novitski wrote:
> At 1/15/2007 01:52 PM, Otto Wyss wrote:
>> When values are entered on one of my page I submit the result back to
>> the same page (form action=same_page). Unfortunately each submit adds
>> an entry into the history, so history back doesn't work in a single
>> step. Yet if the count of submits were known I could use goto(n).
>> What's the best way to get this count? PHP or Javascript?


Lots of overhead here, but basically you need a session var on the
server & a hidden form var on the client.

One session var is the URL of the previous page, when first loaded. Use
isset to determine if you need to seed that var.

Set the other session var to simply increment every time the page loads.

In your form, set the value of the hidden var to the current value of
the session var.

Have the hidden var increment every time the form is submitted.

This will make the session var (on the server) always increment, even if
back is pressed.

The hidden var (on the client) will only increment when the form is
submitted.

You can compare the incrementing values when the page loads to determine
if the back button was pressed, and redirect accordingly.

AFAIK, using the session var is the only way to have a value that the
client can't touch, and thus won't get rolled back to a previous value
when the back button is pressed.

But yikes, the overhead! Hope this isn't a busy page, or your host
likes you.
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Going back with multiple submits to the same page
Old
  (#3)
tedd
Guest
 
Posts: n/a
Default Re: [PHP] Going back with multiple submits to the same page - 05-14-2007, 03:34 AM

At 10:52 PM +0100 1/15/07, Otto Wyss wrote:
>When values are entered on one of my page I submit the result back
>to the same page (form action=same_page). Unfortunately each submit
>adds an entry into the history, so history back doesn't work in a
>single step. Yet if the count of submits were known I could use
>goto(n). What's the best way to get this count? PHP or Javascript?
>
>O. Wyss


Wyss:

Considering that this is client-side (i.e., history), I would look to
javascript, namely:

location.replace('<whatever>');

The location object has two methods: a) reload; b) replace. This is
where the back button get's it's value. Replace that value and I
think you'll find a solution, or at least that's where I would look.

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Going back with multiple submits to the same page
Old
  (#4)
Nick Stinemates
Guest
 
Posts: n/a
Default Re: [PHP] Going back with multiple submits to the same page - 05-14-2007, 03:35 AM

> I already do and currently I just jump to that page but it would be nice
> to go backwards so the user doesn't have to enter the same values all
> the time.


If that is the case, you can also store their values in the session and load them each time.

Just a thought
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Going back with multiple submits to the same page
Old
  (#5)
Otto Wyss
Guest
 
Posts: n/a
Default Re: [PHP] Going back with multiple submits to the same page - 05-14-2007, 03:35 AM

Paul Novitski wrote:
> At 1/15/2007 01:52 PM, Otto Wyss wrote:
>> When values are entered on one of my page I submit the result back
>> to the same page (form action=same_page). Unfortunately each submit
>> adds an entry into the history, so history back doesn't work in a
>> single step. Yet if the count of submits were known I could use
>> goto(n). What's the best way to get this count? PHP or Javascript?

>
>
> What you're suggesting doesn't sound easy.
>

I know, but what's a better way to to go back?

> If you're going to programmatically take the user to a previous page,
> say for example if they click a form button within your page, then
> using JavaScript you could simply walk backward through the
> window.history() array until you came to an URL that doesn't match
> with the current page. Of course such a solution would break if
> JavaScript were disabled so you'd need to build a redundant system
> server-side to make sure your site didn't break.
>

My site already heavily depends on Javascript in many places and my
users can be required to have Javascript enabled.

Just looping through history.back() until a different page is reached
could do the trick. Yet is it possible to have a Javascript value across
multiple pages? Has anybody coded something like this?

Since I already store the last different page, I wounder if I could code
a loop sever side in PHP which issues Javascript "history.back".

> Of course PHP isn't naturally aware of browser history but you could
> store in the session or cookie the name of the last page in the


I already do and currently I just jump to that page but it would be nice
to go backwards so the user doesn't have to enter the same values all
the time.

> functioning of the browser, you could simply let it do its thing and
> take steps server-side to prevent the user from re-submitting the
> current form or whatever your goal is.
>

I thought that too albeit it means to implement XMLHttpRequests instead
of submits to get results from the database. Yet for me this seems to be
more complicated than just going back through the history. My data is
rather large and complicate structured.

O. Wyss
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Going back with multiple submits to the same page
Old
  (#6)
tedd
Guest
 
Posts: n/a
Default Re: [PHP] Going back with multiple submits to the same page - 05-14-2007, 03:35 AM

At 8:43 PM +0100 1/18/07, Otto Wyss wrote:
>Paul Novitski wrote:
>>At 1/15/2007 01:52 PM, Otto Wyss wrote:
>>>When values are entered on one of my page I submit the result back
>>>to the same page (form action=same_page). Unfortunately each submit
>>>adds an entry into the history, so history back doesn't work in a
>>>single step. Yet if the count of submits were known I could use
>>>goto(n). What's the best way to get this count? PHP or Javascript?

>>
>>
>>What you're suggesting doesn't sound easy.
>>

>I know, but what's a better way to to go back?
>


Apparently you didn't get/read my post -- try:

location.replace('<whatever>');

The location object has two methods: a) reload; b) replace. This is
where the back button get's it's value. Replace that value and I
think you'll find a solution, or at least that's where I would look.

As for how to keep your entries "sticky", then I would look to sessions.

tedd

--
-------
http://sperling.com http://ancientstones.com http://earthstones.com
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top