On Mon, Jun 18, 2012 at 12:54:20PM +0100, Greg Thomas wrote:
On 18 June 2012 12:16, Chris Green cl@isbd.net wrote:
So a simpler sequence that simply asks for a response to a question and acts accordingly has the same communication problem:-
Ask user's favourite colour Get favourite colour Set text on page to favourite colour
It's quite complicated to do this from a web application:-
Code creates page with question about colour on it (in my case it's a Wiki page with a PHP plugin called to create the form).
I think this model is probably complicating matters. As someone else suggested (I forget who), it's often easiest to handle the question and the processing of the answer in the same file.
Exactly what I'd love to be able to do but I don't think I can in any of the programming (Wiki etc.) environments I'm using.
So conceptually, it
might look like the following. It's no particular language, but hopefully it helps clear things up. I'm assuming you've got some sort of server side session indicating which user is present.
<% IF Form["FavColour"] is present THEN // They've submitted a colour, so use it FavColour = Form["FavColour"] IF FavColour is valid THEN // save it, and send the user elsewhere UPDATE table SET colour=FavColour WHERE user=Session.userId Redirect("Somewhere") Exit ELSE ErrorMessage = "Sorry, that colour is invalid" END IF ELSE // We don't know the users colour, so fetch it from the database SELECT colour FROM table INTO FavColour WHERE user=Session.userId END IF %>
<form action="THISPAGE"> What's your favourite colour? <input type="text" name="FavColour" text="<%=HTMLEncode(FavColour)%>"> <% If ErrorMesage <> "" Then %> <%=HTMLEncode(ErrorMessage )% <% End If %> <input type="submit" name="Save" </form>
As you say "It's no particular language" but in reality what language and environment can you *actually* do this? It would be possible with a stand-alone page created using PHP I suppose but in the real world this doesn't integrate well into other applications.
E.g. it should be possible to have a high-level/parent process that both serves the pages (my Wiki software - called by apache) *and* collects the reply when the user sends it back such that one can run a conceptually single-threaded process to both ask the question and handle the reply with some sort of common environment etc.
You could do this, but it's not conceptually how the WWW works. It was designed originally to be stateless (which makes it more scaleable), and the model you suggest isn't. Now, state has since been introduced, typically by using cookies or URLs to store a session id, but that's a different solution.
Quite!