473,473 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Best way to create object from a form with lots of fields

I have multiple forms that will create an object. Basically a energy
efficiency measure object. The measure object will have a couple of
required properties set but after that it can have 10-20 different fields
that are optional per measure.

How do I account for the different fields that will be
posted from the different forms when I create the measure object? Should
I create a constructor method with just the required fields as the
parameters and then create some sort of setter method for the optional
fields? Or do I create a different concrete measure object from an an
abstract measure base class? I have about 10 different measure objects
that I can think of but really the only difference between them are what
optional fields are posted.

Going forward the other issue is I need these measures to persist across
the pages of the application (sort of like a shopping cart app) and I see
that I can serialize an object in a $_SESSION object but do the fields
that I would set in the setter method also get serialized or do only the
actual properties of the object get set.

I then need to retrieve all these measure objects and send them to a
stored procedure to enter into a database so unfortunately I can't save
the fields as serialized because each field has to be separate to be sent
as the parameters to the stored procedure.

Basically my question is how do people deal with huge forms and fields
easily from a html post? Any help would be appreciated...thanks...

P.S. Using ZendFramework1.0RC2 and PHP5.
Jun 22 '07 #1
1 2442
Dave wrote:
I have multiple forms that will create an object. Basically a energy
efficiency measure object. The measure object will have a couple of
required properties set but after that it can have 10-20 different fields
that are optional per measure.

How do I account for the different fields that will be
posted from the different forms when I create the measure object? Should
I create a constructor method with just the required fields as the
parameters and then create some sort of setter method for the optional
fields? Or do I create a different concrete measure object from an an
abstract measure base class? I have about 10 different measure objects
that I can think of but really the only difference between them are what
optional fields are posted.
Hi Dave,

If the only difference is really what optional fields are to be in the
form, i would use a single Measure class and ten different layouts for
the forms.

In any case i do not like the idea of a contructor with the required
fields as parameters:
1. Validating the field values is typically a task of the object, it is
kind of hard to ask the object to do that if it has not yet been contructed,
2. If you change your mind and decide that some of the required fields
should not have been required, or some of the optional fiels are to be
required, you have to change the constructor, and all the calls that are
made to it.

A better apoach is to use meta data to declare wheather a field is
required or optional. When the form is processed you simply let the
object check if each of the required fields is holding valid data and
produce user-understandable error feedback if necessary.
>
Going forward the other issue is I need these measures to persist across
the pages of the application (sort of like a shopping cart app) and I see
that I can serialize an object in a $_SESSION object but do the fields
that I would set in the setter method also get serialized or do only the
actual properties of the object get set.

I then need to retrieve all these measure objects and send them to a
stored procedure to enter into a database so unfortunately I can't save
the fields as serialized because each field has to be separate to be sent
as the parameters to the stored procedure.
If the system is for a small audience of authenticated users i would
store the Measure objects in a database table of pending measures and
give them the user name as a foreign key. Then if a user returns he will
not have lost all of the measures he has already submitted. If he has
finished entering measures he should press a button or so to store all
pending measures in the final database. If successfull this will delete
his pending measures.

If the system is for a large audience of unauthenticated users, like a
shopping cart, i would store the pending measures in the session. But I
would not use serialize on the object itself but on an array with the
field names as keys and their values as values. That way there will not
be any errors because of the class not yet being included or being renamed.
>
Basically my question is how do people deal with huge forms and fields
easily from a html post? Any help would be appreciated...thanks...

P.S. Using ZendFramework1.0RC2 and PHP5.
IMHO the framework should offer a way to declare the meta data and take
care of the conversion and validation of form values.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.
Jun 25 '07 #2

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

Similar topics

10
by: Bob Bedford | last post by:
Sorry if I post here, but I don't have access to any valuable mysql ng for this question, ans since 99% or php programmers deal with mysql, I'm sure I'll get an answer here. Look at the...
4
by: David | last post by:
Hello. I am looking for advice on what is "best practice" regarding looping through a form to check its checkboxes and associated data fields. Here is what I am trying to do (Here is the page...
1
by: Chris Uwins | last post by:
Hi there, i know theres a number of ways I can achieve this but want to know the best, (but still quite simple). Up until a year ago I never used Access but have designed a few databases for...
6
by: skgolden | last post by:
My husband and I own a small temporary labor company and deal with 4 major clients (A,B,C & D), each of which has about 2 dozen units in our tristate area that we deal with (ie, Company A, units...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
4
by: MicroMoth | last post by:
Hi, I'm trying to write a update method, in which when the user clicks the update button the update method is passed 10 form fields. Then a update SQL is run to update the database. My question...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.