You are here: Re: New ideas « PHP Programming Language « IT news, forums, messages
Re: New ideas

Posted by Umberto Salsi on 05/21/07 05:02

"Jon Slaughter" <Jon_Slaughter@Hotmail.com> wrote:

> Again, the main idea is to treat form evaulation as inline instead of on a
> seperate page. In this way one encapsulates the function of the form with
> the form itself. [...]

I agree with you that embedding all the code that handle related WEB pages
(the typical example is handling the loop form display, validation, error
reporting, acquisition of the data) is very powerful, and it can implemented
in several ways. Adding "embedded strings with PHP code" may be a pain,
as you experienced. But things can be improved. Some idea follows.


[ Function bound to an URL ]

Rather than add chunks of code as inline strings and send them as cookies,
you might want to consider to associate every "action" to a PHP function.
That is what i called "programming the WEB application by functions".

Then a single PHP source may contain several functions calling each other
via "actions". For example, this function generates a page with 3 anchors
that, once selected by the user, causes the correspondin function/action
handler to be called; handlers can have also arguments:

function Home()
{
PageHead();
echo "<h1>Wellcome in our beautiful WEB site!</h1>";
echo "Please, select a page:";
Anchor("Page 1", 'Page1');
Anchor("Page 2", 'Page2', 'x', 'the_value_of_x');
Anchor("See the source", 'SeeSource');
PageFoot();
}

where the arguments of the Anchor() function are:

- the text of the anchor (what the user actually will see)
- the name of the PHP function to be called if this anchor get clicked
- the name and value of zero or more arguments to be passed to the function

The example of this solution is availabe on my WEB site along the source
at http://www.icosaedro.it/php/esempio1.cgi, that implements several sample
WEB pages in a single PHP source. This simple program can handle only
GET requests.


[ Handling also the POST method ]

A more refinite example that handle also POST requests is available here:
http://www.icosaedro.it/php/esempio2.cgi
Anchors are handled just as before. Creating a FORM is very simple:

function InputForm()
{
Form();
echo "Write here a string: <INPUT type=text name=s value=\"\">";
Button("Cancel", 'Home');
Button(" OK ", 'InputForm_POST');
Form_();
}

where the arguments of Button() are:

- the text of the button
- the PHP function to call once this button is pressed
- the arguments of the function, if any

So, for example, if the "Cancel" button will be pressed, the function Home()
will be called. The informations about functions and associated arguments are
stored inside hidden fields of the FORM and protected from tampering via HMAC.


[ bt_ ]

An even more refined solution I'm currently using is what i called "bt_
framework". bt_ is suitable for modal applications whose reference model are
the stand-alone applications rather than the WEB, i.e. the user is forced
to follow the path established by the application, and it cannot jump here
and there between the pages because every page is bound to some internal
state of the WEB application.

The HTML code generated by bt_ is very light, since no hidden fields are
required: all the informations that represent the status of the WEB appl.
are stored in the session, so these informations don't go back and forward
between the client and the server.

bt_ implements also a sorta of "stack of the calls", with which the WEB
application becomes something really similar a regular applications, with
"jump to subroutine" statements (the functions bound to anchors and buttons)
and the "return from subroutine" statements. The typical application
of the stack is handling generic pages that need to show something to the
user, then need to return to the calling page, whatever this page can be.

For example, this page displays the current date and the button "OK"
that send back to the calling page:

function show_date()
{
echo "The current date is: ", date(....);
Form();
Button("OK", "bt_return"); # return to the caller page
Form_()
}

This page might appear in several contexts of the WEB application:

function main_menu()
{
echo "<h1>Main menu</h2>"

bt_Anchor("See the current date", "show_date");
bt_Return_To("main_menu"); # back to me on "bt_return()"
}

function another_page()
{
echo "<h1>Another page</h2>"

bt_Anchor("See the current date", "show_date");
bt_Return_To("another_page"); # back to me on "bt_return()"
}


Hope this may contribute to your idea.

Regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация