473,396 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

PHP - Best (or better) practice for Forms?

I have a web app that is forms intensive. These forms have a number
of dropdown lists, check box, etc., each which requires additional
processing, db calls, etc. On an item changed, I post back the form
and set a hidden field to tell PHP what changed so it knows what to
process.

Is there a preferred way to handle this type of forms processing? My
screen is a mix of hidden vars., Javascript, etc. which works but it
messy!

I guess I am looking for a web site of book on "The Zen" of php! Eg.
not so much how but how AND why.

Thanks

Sep 5 '05 #1
9 1578
David said the following on 05/09/2005 23:58:
I have a web app that is forms intensive. These forms have a number
of dropdown lists, check box, etc., each which requires additional
processing, db calls, etc. On an item changed, I post back the form
and set a hidden field to tell PHP what changed so it knows what to
process.


This relies on Javascript being enabled, and is a waste of bandwidth
(you need to send a load of extra HTML, and the form submission requires
a load of extra fields).

Why do you need to know exactly what was changed? Why not just update
everything when you've received the form submission?

If you're worried about speed, it will make virtually zero speed
difference whether you update one field in a table row, or the whole row.

If you need to identify changes in values to trigger specific actions,
then either extract the original values from the DB and do a comparison
server-side, or store the original values in $_SESSION.
--
Oli
Sep 5 '05 #2
The use of hidden fields to hold the "original value" of a field is bad
practice. If the field is modified in the mean time (through a
different window, for instance) then the forms will not be fully saved.

You don't get much from this kind of optimization. Just resave the
whole thing.

Sep 6 '05 #3
On Mon, 05 Sep 2005 17:58:40 -0500, David wrote:
Is there a preferred way to handle this type of forms processing? My
screen is a mix of hidden vars., Javascript, etc. which works but it
messy!


require_once('HTML/QuickForm.php');

--
http://www.mgogala.com

Sep 6 '05 #4
On 5 Sep 2005 20:42:33 -0700, Chung Leong wrote:

Have you ever considered quoting what your replying to?
Sep 6 '05 #5
Rincewind wrote:
On 5 Sep 2005 20:42:33 -0700, Chung Leong wrote:

Have you ever considered quoting what your replying to?


Hi Rincewind,

Most of us use a threaded newsreader.
What do you use?
Do you receive all there mails in your mailbox without a structure?
If so: why not start using a newsreader?
Many opensourced/free newsreaders are available.

Or do you have another reason to complain?
(I am just curious.)

Regards,
Erwin Moller
Sep 6 '05 #6
On Tue, 06 Sep 2005 15:55:48 +0200, Erwin Moller wrote:
Rincewind wrote:
On 5 Sep 2005 20:42:33 -0700, Chung Leong wrote:

Have you ever considered quoting what your replying to?


Hi Rincewind,

Most of us use a threaded newsreader.
What do you use?
Do you receive all there mails in your mailbox without a structure?
If so: why not start using a newsreader?
Many opensourced/free newsreaders are available.

Or do you have another reason to complain?
(I am just curious.)

Regards,
Erwin Moller


1. Because it's the way Netiquette wants it.

2. Because I don't always receive all posts that are sent so it make no
difference what newsreader I use if it ain't there I can't read it.

3. If you want to know what newsreader I, or anyone else uses read the
headers, you for instance use KNode 0.7.1 and you post through
news.xs4all.nl server. ;-))
Sep 6 '05 #7
The issue is changes in a dropdown box will require the app to perform
a DB lookup.

If the user changes a dropdown box, how can one tell the system to
postback and then what caused that postback. Unless you session all
of the vars or keep a hidden version of each, then you need to set
some switch to tell the system what occurred!

I will say this is MUCH easier in ASP.net.

This relies on Javascript being enabled, and is a waste of bandwidth
(you need to send a load of extra HTML, and the form submission requires
a load of extra fields).

Why do you need to know exactly what was changed? Why not just update
everything when you've received the form submission?


Sep 8 '05 #8
The issue is changes in a dropdown box will require the app to perform
a DB lookup.

If the user changes a dropdown box, how can one tell the system to
postback and then what caused that postback. Unless you session all
of the vars or keep a hidden version of each, then you need to set
some switch to tell the system what occurred!

I will say this is MUCH easier in ASP.net.
As a matter of security and an matter of bandwidth it's always better to determine your changes in the resultant web page your are submiting to. Get a extra hit to the database, query and build your update via PHP. Better yet though if you where running against MS SQL you'd do it in a trigger at the database, if your running in MYSql version five you'd also run it in a trigger on the database. If you can do it in a trigger always try there first. You can code update times, copy old records to log tables etc.. all via triggers.

:cool: MYSQL Tigger Docs
:cool: MS SQL Trigger Docs
Sep 9 '05 #9
David wrote:
I have a web app that is forms intensive. These forms have a number
of dropdown lists, check box, etc., each which requires additional
processing, db calls, etc. On an item changed, I post back the form
and set a hidden field to tell PHP what changed so it knows what to
process. When processing form on server just compare entered data and current
data from database to know that is changed. I use class for it who make
'changed' attribute for every db field so I can just check attribute.
Is there a preferred way to handle this type of forms processing? My
screen is a mix of hidden vars., Javascript, etc. which works but it
messy!

All javascript code must be in one separate .js file. just link to it
on your form page and call procedure with one long-long parameter
describing all tests for this form. as here for example:
http://www.crimaniak.com/flat/
(see source, search for <form> tag)
Sep 9 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John Pastrovick | last post by:
I am not sure what the most effective way to organize a db for users is. I have 40 users (teachers) and 20 tables (grades, assignments, students, etc). Each needs access to its OWN grades,...
52
by: Andy Dingley | last post by:
I'm using this at present: <p title="Publication date" ></p> Works fine on screen, but Fangs/Jaws just reads it as "left bracket twenty-eight slash zero slash two thousand five fifteen colon...
6
by: John | last post by:
I have a question about design, performance, and code reusability. Which one of these would be the best as far as performance/speed Send a textbox to a public class to check it and process/not...
1
by: JustMe | last post by:
Hi all, Although I've got quite a lot of experience with php and (M/My)SQL, I only used both within an online php script. These last few months I bought an option with my webhost to access...
2
by: =?iso-8859-1?q?Marcos_Jos=E9_Setim?= | last post by:
Hi, I would like to know if is better to use document.forms to detect forms or getElementById. Thanks
5
mythescriptid
by: mythescriptid | last post by:
Hi All, I know templates and STL might have been discussed many a times here, I'm bit of newbie as far as templates are concerned and was itching to test my new found linking of templates. I would...
52
by: burgermeister01 | last post by:
First, let me say that this question is a rather general programming question, but the context is PHP, so I figured this group would have the most relevant insight. Anyways, this is also more of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.