Re: New to PHP, need pointers to best practices for the design of an atypical web app
| From: | Alan Mead | Date: | Tue, 02 Jul 2019 05:17:43 +0000 |
| Subject: | Re: New to PHP, need pointers to best practices for the design of an atypical web app | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-326840@lists.php.net to get a copy of this message | ||
I agree that "postback" seems to be what I'm interested in. Thanks for
showing me this term.
-Alan
On 7/1/2019 11:48 PM, Sam Hobbs wrote:
> One essential framework is education. You need to use it.
>
> There are many others around here that can help you better than I.
> Until they do, you can read about post-backs as in the following.
> These won't explain everything; you can search for additional
> material. But it is likely your solution will include post-backs.
>
> * PHP: $_POST - Manual
>
> <https://www.php.net/manual/en/reserved.variables.post.php>
> * forms - PHP postback on submit - Stack Overflow
>
> <https://stackoverflow.com/questions/13223398/php-postback-on-submit>
> (one response mentions Sessions
> <https://php.net/manual/en/features.sessions.php>
> except the
> German help page)
> * http - Detecting request type in PHP (GET, POST, PUT or DELETE) -
> Stack Overflow
>
> <https://stackoverflow.com/questions/359047/detecting-request-type-in-php-get-post-put-or-delete>
>
> Generally in a post-back the page is posted back to the server and the
> page detects that it is a post-back and does relevant (different)
> processing. And yes, post-backs are complicated (technical) but it is
> necessary to learn about them. Websites were not initially designed to
> do everything that people are using them for now so some things are
> not as easy as they could be.
>
>> Alan Mead <mailto:amead@alanmead.org>
>> Monday, July 1, 2019 12:45 PM
>> I want to implement an adaptive test (exam) using PHP. (So, like any
>> quiz, or any multi-page form, but using internal logic to decide what
>> question to serve next and deciding when the exam is done.) I am a
>> researcher (not a programmer) but I am familiar with Perl and other
>> programming languages and with some web application models.
>>
>> It looks like the vast majority of the PHP examples use the page
>> (perhaps with parts dynamically injected using PHP) to represent the
>> "mode" (state) of the application. I definitely want to separate my
>> logic/code from presentation, but AFAICT the popular frameworks all
>> use a MVC pattern where the "mode" is encoded in the URL (which is
>> really the same since the URL specifies the page).
>>
>> I don't think an exam fits well with either of these models. Even in
>> research, a test-taker completing an exam should proceed linearly
>> through a series of screens (consent, instructions, a series of
>> items, optionally some post-questionnaire questions, optionally some
>> exam results, some kind of "thank you"). And the examinee should not
>> have any ability to modify the sequence of screens or the
>> backend/underlying data by manipulating the URL.
>>
>> Also, one of my design goals is to allow the researcher (who would
>> install and configure this software) to control whether the optional
>> pages appear and to modify templates to include their own content on
>> these pages.
>>
>> My inclination is to create a large index.php file that examines the
>> user input and the current state and executes a subroutine that
>> serves the appropriate next page (by selecting the appropriate
>> template and filling it with appropriate information). I know this is
>> atypical and I'd appreciate thoughts about things I may be
>> overlooking as a newcomer to PHP and the PHP way of creating web
>> apps. If I'm reinventing any wheels, I'd appreciate pointers to those
>> frameworks.
>>
>> I'm also having trouble finding a simple example of using a template
>> outside of a framework. But maybe that's my newness...
>>
>> -Alan
>> --
>>
>> Alan D. Mead, Ph.D.
>> President, Talent Algorithms Inc.
>>
>> science + technology = better workers
>>
>> http://www.alanmead.org
>>
>> "You're an interesting species. An interesting mix.
>> You're capable of such beautiful dreams, and such
>> horrible nightmares. You feel so lost, so cut off,
>> so alone, only you're not. See, in all our
>> searching, the only thing we've found that makes
>> the emptiness bearable, is each other."
>>
>> -- Carl Sagan, Contact
>> Sam Hobbs <mailto:Sam@SimpleSamples.info>
>> Monday, July 1, 2019 8:58 PM
>> I don't know how much you know so I apologize if I am telling youi
>> anything you already know.
>>
>> You need to understand the fundamentals of how the HTTP protocol and
>> HTML work. Initially in the world wide web browsers would send a
>> request for a page to the server and the server would read the HTML
>> file and send it to the client (the browser). If that is new to you
>> then there are thousands of places you can learn more. The important
>> thing is that the server forgets about the request. There is nothing
>> left in the server. The server is done with the request.
>>
>> Also in the early days of the internet HTML had forms but they were
>> very basic compared to how they are currently used. Initially a form
>> would have a submit button that would send the form contents to the
>> server. Normally the server would execute a Common Gateway Interface
>> (CGI) program. The CGI program would write out a HTML file that was
>> sent to the client. Alternatively the server would show a second HTML
>> file but that is not relevant here. The important thing is that PHP
>> uses the same CGI technology. PHP reads a HTML file (except with PHP
>> in it) and writes out a HTML file that is sent to the client. And
>> here it gets complicated. Over the years various techniques have been
>> developed so that server-side programming could retain and/or send
>> data across requests. One way is for data in a page to be sent as
>> part of a request that has the relevant data.
>>
>> Well there is much more to the story. If any of that is new to you
>> then you have some reading to do.
>>
>> There are two general possible solutions to your requirements, but
>> there are many more possibilities too. One possibility would be to
>> send all the data to the client and do all the work in the client
>> using JavaScript or some client-side programming. That could provide
>> the best performance but requires you to use JavaScript and would
>> compromise security. Another possibility is something called a
>> post-back and that is quite technical. It is however using technology
>> much like an old-style HTML form except generalized and made more
>> technical.
>>
>>
>> Alan Mead <mailto:amead@alanmead.org>
>> Monday, July 1, 2019 9:12 PM
>> Thanks. JS isn't an option because the adaptive algorithm needs to
>> score the items and I don't consider it secure to send the answer
>> keys of an exam to a client-side script.
>>
>> So, if you were me, what PHP framework or app model would you use?
>>
>> -Alan
>>
>>
>> On 7/1/2019 10:58 PM, Sam Hobbs wrote:
>>
>> --
>>
>> Alan D. Mead, Ph.D.
>> President, Talent Algorithms Inc.
>>
>> science + technology = better workers
>>
>> http://www.alanmead.org
>>
>> "You're an interesting species. An interesting mix.
>> You're capable of such beautiful dreams, and such
>> horrible nightmares. You feel so lost, so cut off,
>> so alone, only you're not. See, in all our
>> searching, the only thing we've found that makes
>> the emptiness bearable, is each other."
>>
>> -- Carl Sagan, Contact
>
--
Alan D. Mead, Ph.D.
President, Talent Algorithms Inc.
science + technology = better workers
http://www.alanmead.org
"You're an interesting species. An interesting mix.
You're capable of such beautiful dreams, and such
horrible nightmares. You feel so lost, so cut off,
so alone, only you're not. See, in all our
searching, the only thing we've found that makes
the emptiness bearable, is each other."
-- Carl Sagan, Contact