Postback Implementation

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Postback Implementation

Post by JNettles »

Has anyone ever built a page state system for PHP? If so, what was your methodology for its operation? Right now I'm toying with the idea of creating a hidden field with the original control value for each control on the page - any thoughts? This is part of my grand design to create a light-weight framework for PHP that is similar to .NET.
nshiell
Forum Newbie
Posts: 12
Joined: Mon Oct 19, 2009 12:20 pm

Re: Postback Implementation

Post by nshiell »

I don't know .net
What are you ACTUALLY trying to do? Page State?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Postback Implementation

Post by Christopher »

Can you give us some example use cases of what you want the code that uses this Postback system to look like?
(#10850)
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Postback Implementation

Post by JNettles »

Sorry, I guess I thought more people knew what it was off the top of their heads. I work in .NET just as much as I do PHP and so I hear "postback postback postback" all day long.

You have a form with several textboxes. Typically, you would post these textboxes to another page, or a different section of a page (from index.php?page=form gets posted to index.php?page=process_form). In my method, information is posted back to the same page along with an event to be fired (like btn_Submit) that handles the post data. The difference is that while the page is reloaded, it reloads to its original state so that even though you've reloaded, the values you had in your form persist.

I'm not explaining this well. Postback. This is just a theoretical question of implementation, ie: better to use sessions, cookies, post data, etc etc.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Postback Implementation

Post by Christopher »

JNettles wrote:Sorry, I guess I thought more people knew what it was off the top of their heads. I work in .NET just as much as I do PHP and so I hear "postback postback postback" all day long.
I think people know what "postback" means. But what specific style of form handling code are you looking for?
JNettles wrote:You have a form with several textboxes. Typically, you would post these textboxes to another page, or a different section of a page (from index.php?page=form gets posted to index.php?page=process_form). In my method, information is posted back to the same page along with an event to be fired (like btn_Submit) that handles the post data. The difference is that while the page is reloaded, it reloads to its original state so that even though you've reloaded, the values you had in your form persist.

I'm not explaining this well. Postback. This is just a theoretical question of implementation, ie: better to use sessions, cookies, post data, etc etc.
There are hundreds of forms managers that do this kind of thing in almost every way imaginable in PHP. Every major framework has an implementation too. So the question is -- what do you want your forms code to look like?
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Postback Implementation

Post by alex.barylski »

What framework are you using?

What you need to do is forward the event handling request back to the form controller and all GPC values are persisted. If your using something like CodeIgnitor (which I don't believe supports forwarding) than you need to persist using SESSION's or similar -- which is a hack if you ask me.

Cheers,
Alex
wei
Forum Contributor
Posts: 140
Joined: Wed Jul 12, 2006 12:18 am

Re: Postback Implementation

Post by wei »

already done about 5 years ago, http://pradosoft.com/ provides post back et. al.
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Postback Implementation

Post by JNettles »

Thanks, but I've been using Prado for several years now. This is for my own custom framework - which is meant to be lightweight, superfast, and leaves little footprint on the server. Not that I don't find other frameworks like Zend, Prado, Joomla, and Cake to be fantastic options but all of them are rather bulky, have a medium to high learning curve, and are comparatively slow. Mine is a home-brew MVC implementation that I use for rapid small-scale development and is easily modified by my clients. Its a three file framework -> an index, a configuration, and a framework file that handle all operations. Its as easy as dump in a CSS, HTML markup files, PHP code-behinds and data models if you need them, and you're ready to go.

I'm working on a new version that is page-event based (ala Prado) and Postback is something I'm looking to fine-tune. I already have a working model using a special session manager but I was trying to entertain other ideas as I would like to stay out of the session altogether if I can but it doesn't look like it.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Postback Implementation

Post by Jenk »

You might have better luck when searching for their proper name "callback." MS have done their usual trick of taking an existing idea, rebranding it, then selling as a new innovation.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Postback Implementation

Post by alex.barylski »

Callback? Seriously? I have no idea how MS implements a postback, but it's really not that complex of an operation with a properly designed framework. Zend for instance fully supports postback, via a forward, from within your actions.

A forward is like an internal redirect, so any POST data is not destroyed by the time the forward'ed action recevies the request, thus allowing you to re-populate the FORM with POST'ed data.

The reason you are running into this issue, is because you are using a custom built framework.

Bulky is a common complaint with full stack frameworks, and I can't argue otherwise, they are. But until you implement a proper front controller and actions, etc, you will continue running into architectural issues, such as postback, and re-inventing the wheel, likely with hackish solutions, like using SESSION for persisting data across POST requests.

Cheers,
Alex
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Postback Implementation

Post by Christopher »

That's why I asked what he wanted the code that uses this "postback" system to look like. It might be an interesting discussion of some different ways to implement this in PHP.
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Postback Implementation

Post by alex.barylski »

That's why I asked what he wanted the code that uses this "postback" system to look like. It might be an interesting discussion of some different ways to implement this in PHP.
It could be, especially for multiple form submission wizard like interfaces.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Postback Implementation

Post by Jenk »

Haven't used it myself, but as it is based on Seaside (a Smalltalk web-framework that I use all the time) Phaux should have callbacks.
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: Postback Implementation

Post by JNettles »

But until you implement a proper front controller and actions, etc, you will continue running into architectural issues, such as postback, and re-inventing the wheel, likely with hackish solutions, like using SESSION for persisting data across POST requests.
ie: Why I asked for suggestions in the first place. I'm not happy with the way I currently am doing it, which is with a session, and I'm trying to keep the session free since my goal is for this to be as unobtrusive as possible. No possible interference or confliction from the framework.

This is standard MVC pattern - controller up front grabbing pages, code-behind, DOM parsing, and rendering.

I suppose that since I control the HTML output I could have the DOM create hidden fields with callback data for all fields inside of a form......
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Postback Implementation

Post by alex.barylski »

I'm just curious now, but how does ASP Implement POSTBACK?

They seem to use SESSION's and a _postbackID or something in the cookie to lookup the serialized data? How then does it handle clearing the cache when the form is successfully submitted or navigated away from?

Does anyone have intimate knowledge or insight into how ASP accomplishes this task? How about Prado?
Post Reply