Thread: Stroring html form settings

Stroring html form settings

From
Dianne Yumul
Date:
Hello,

I have some html forms that I save the settings into the database,
things like which item was selected in the menu and if a checkbox was
checked. The table looks like this:

  user_id | report_id |                      info
---------+-----------+------------------------------------------------
      111 |         1 | A:::::CHECKED::::CHECKED::::CHECKED::
      111 |         2 | A:::CHECKED::
      111 |         3 | A::CHECKED:CHECKED::CHECKED::::CHECKED:::

The info column has the settings separated with a : and consecutive
colons mean the user didn't make a selection. Would this be the way
to store them?

I've done some searching and I could use XML (I will read some
tutorials after writing this email). But there may be other ways and
I'm just too much of a newbie to know. I'm using Postgresql 8.1.11
and PHP on CentOS 5.2.

Thanks in advance.

Dianne

Re: Stroring html form settings

From
"Jeff Soules"
Date:
On Thu, Sep 25, 2008 at 5:38 PM, Dianne Yumul <dianne@wellsgaming.com> wrote:
> Hello,
>
> I have some html forms that I save the settings into the database, things
> like which item was selected in the menu and if a checkbox was checked. The
> table looks like this:
>
>  user_id | report_id |                      info
> ---------+-----------+------------------------------------------------
>     111 |         1 | A:::::CHECKED::::CHECKED::::CHECKED::
>     111 |         2 | A:::CHECKED::
>     111 |         3 | A::CHECKED:CHECKED::CHECKED::::CHECKED:::
>
> The info column has the settings separated with a : and consecutive colons
> mean the user didn't make a selection. Would this be the way to store them?
>
> I've done some searching and I could use XML (I will read some tutorials
> after writing this email). But there may be other ways and I'm just too much
> of a newbie to know. I'm using Postgresql 8.1.11 and PHP on CentOS 5.2.
>
> Thanks in advance.
>
> Dianne

Hi Dianne,

My first thought is that if you use a combined "info" field, you'll
lose the ability to easily do any kind of meaningful data analysis
based on which boxes are checked.  If you just want to record what a
given user said at a certain time, but don't need it for any other,
more interesting evaluation of the data, then why bother with a
database?  Also, if the form structure & options etc. are at all
subject to change, you've eliminated the possibility of doing data
integrity checks and you may wind up with a code in the "info" field
that is out of date relative to what the form looks like now, i.e. the
"info" field was filled when the values corresponded to something
different from what they mean at read-time.
An XML format might be one way to record key-value pairs, and avoid
the possibility of new interpretations of the code invalidating your
old data, but from the database perspective, actually storing XML is
space-intensive, kinda clunky, and doesn't really leverage the things
you can do with a database.

If it were me, I would probably store the form values in the database
fields, so that the table's columns matched the various data inputs in
the form.  (That's if you don't expect the form structure to change a
whole lot).  Then again, I'm probably the least experienced person on
this list, so I'm sure I'll be corrected shortly : )

Best,
Jeff

Re: Stroring html form settings

From
Martin Gainty
Date:
which webserver does your client want to implement?
if webserver is Apache does your client favor any JavaScript Library <Dojo/Scriptaculous/Flex> ?
If JSLibrary = Dojo I would look at JSON (JavaScript Object Notation language)
http://today.java.net/pub/a/today/2006/04/27/building-ajax-with-dojo-and-json.html

if you want a full service multi-threaded solution you can implement your Dojo controls delivering JSON results
to Struts
http://struts.apache.org/2.0.11.2/docs/dojo-head.html

Martin
______________________________________________
Disclaimer and confidentiality note
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission.


> To: pgsql-general@postgresql.org
> From: dianne@wellsgaming.com
> Subject: [GENERAL] Stroring html form settings
> Date: Thu, 25 Sep 2008 14:38:20 -0700
>
> Hello,
>
> I have some html forms that I save the settings into the database,
> things like which item was selected in the menu and if a checkbox was
> checked. The table looks like this:
>
> user_id | report_id | info
> ---------+-----------+------------------------------------------------
> 111 | 1 | A:::::CHECKED::::CHECKED::::CHECKED::
> 111 | 2 | A:::CHECKED::
> 111 | 3 | A::CHECKED:CHECKED::CHECKED::::CHECKED:::
>
> The info column has the settings separated with a : and consecutive
> colons mean the user didn't make a selection. Would this be the way
> to store them?
>
> I've done some searching and I could use XML (I will read some
> tutorials after writing this email). But there may be other ways and
> I'm just too much of a newbie to know. I'm using Postgresql 8.1.11
> and PHP on CentOS 5.2.
>
> Thanks in advance.
>
> Dianne
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general


See how Windows Mobile brings your life together—at home, work, or on the go. See Now

Re: Stroring html form settings

From
Marcus Engene
Date:
Dianne Yumul wrote:
> Hello,
>
> I have some html forms that I save the settings into the database,
> things like which item was selected in the menu and if a checkbox was
> checked. The table looks like this:
>
>  user_id | report_id |                      info
> ---------+-----------+------------------------------------------------
>      111 |         1 | A:::::CHECKED::::CHECKED::::CHECKED::
>      111 |         2 | A:::CHECKED::
>      111 |         3 | A::CHECKED:CHECKED::CHECKED::::CHECKED:::
>
> The info column has the settings separated with a : and consecutive
> colons mean the user didn't make a selection. Would this be the way to
> store them?
>
> I've done some searching and I could use XML (I will read some
> tutorials after writing this email). But there may be other ways and
> I'm just too much of a newbie to know. I'm using Postgresql 8.1.11 and
> PHP on CentOS 5.2.
>
> Thanks in advance.
>
> Dianne
>
Hi,

I would serialize to JSON instead of XML.
http://www.aurore.net/projects/php-json/

A simple json_encode($_POST) might do the trick. You could either use
json_decode() to make a PHP struct of it or send it more or less as it
is to Javascript.

I usually find XML horrible to work with in a web context.

Best regards,
Marcus


Re: Stroring html form settings

From
Dianne Yumul
Date:
First, I want to thank you for your help. You have made great points
and I just want to respond to some of your questions.

> My first thought is that if you use a combined "info" field, you'll
> lose the ability to easily do any kind of meaningful data analysis
> based on which boxes are checked.  If you just want to record what a
> given user said at a certain time, but don't need it for any other,
> more interesting evaluation of the data, then why bother with a
> database?

You are right that I don't really need to do any evaluation of the
data, I just need to be able to get the default values of a form
every time the user logs on. Each user may have their own default
value for a form, and each form will have different components. A
database was the first (may be not the best?) thing I thought of.
Would you have other suggestions of how I should store them?

> If it were me, I would probably store the form values in the database
> fields, so that the table's columns matched the various data inputs in
> the form.

If the structure of each report did not differ this would work great
but unfortunately it does.

Thank you again.

Dianne

Re: Stroring html form settings

From
Dianne Yumul
Date:
which webserver does your client want to implement?

Apache, sorry I forgot to mention.

If JSLibrary = Dojo I would look at JSON (JavaScript Object Notation language)

I would serialize to JSON instead of XML.

A simple json_encode($_POST) might do the trick. You could either use json_decode() to make a PHP struct of it or send it more or less as it is to Javascript.

It looks like JSON is what we need. Would you suggest storing the key/value pairs in the same info field on the database table?

Thank you very much Martin and Marcus. 

Re: Stroring html form settings

From
Martin Gainty
Date:
I would suggest trying to keep architecture simple with a one-to-one correspondence between
Architecture classes and the class attributes and DB Tables and the DB table's columns
This will come in handy when and if you want to look at ORM tools to persist the class attributes
to DB tables and columns via Hibernate or IBatis
here is a great example which details a Table called Honey and a class called Honey which will persist class contents to the PostGRES DB by utilising the methods available from InitSessionFactory

http://www.laliluna.de/first-hibernate-example-tutorial.html

HTH
Martin
______________________________________________
Disclaimer and confidentiality note
Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission.


> From: dianne@wellsgaming.com
> Subject: Re: [GENERAL] Stroring html form settings
> Date: Fri, 26 Sep 2008 09:23:21 -0700
> To: pgsql-general@postgresql.org
>
> First, I want to thank you for your help. You have made great points
> and I just want to respond to some of your questions.
>
> > My first thought is that if you use a combined "info" field, you'll
> > lose the ability to easily do any kind of meaningful data analysis
> > based on which boxes are checked. If you just want to record what a
> > given user said at a certain time, but don't need it for any other,
> > more interesting evaluation of the data, then why bother with a
> > database?
>
> You are right that I don't really need to do any evaluation of the
> data, I just need to be able to get the default values of a form
> every time the user logs on. Each user may have their own default
> value for a form, and each form will have different components. A
> database was the first (may be not the best?) thing I thought of.
> Would you have other suggestions of how I should store them?
>
> > If it were me, I would probably store the form values in the database
> > fields, so that the table's columns matched the various data inputs in
> > the form.
>
> If the structure of each report did not differ this would work great
> but unfortunately it does.
>
> Thank you again.
>
> Dianne
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general


Get more out of the Web. Learn 10 hidden secrets of Windows Live. Learn Now

Re: Stroring html form settings

From
Reece Hart
Date:
On Fri, 2008-09-26 at 09:23 -0700, Dianne Yumul wrote:
If the structure of each report did not differ this would work great 
but unfortunately it does.

Diane-

Would an EAV model work? I'm thinking something like <form,field,value>. For example:
formA,ckbox1,true
formA,input1,initial value
formB,textarea1,enter your long comment here

You could easily extend this to <user,form,field,value>, or normalize it as you see fit.

Another possibility is to use hstore hashes for form fields/values. See
http://www.postgresql.org/docs/8.3/static/hstore.html

Do either of those suffice?

-Reece

-- 
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0

Re: Stroring html form settings

From
Dianne Yumul
Date:
Would an EAV model work? I'm thinking something like <form,field,value>. For example:
formA,ckbox1,true
formA,input1,initial value
formB,textarea1,enter your long comment here

You could easily extend this to <user,form,field,value>, or normalize it as you see fit.

This would work great too. If we go this route, we'll keep it simple and use the <user_id, report_id, field, value>, as you suggested, where user_id and report_id are foreign key references.

Another possibility is to use hstore hashes for form fields/values. See
http://www.postgresql.org/docs/8.3/static/hstore.html

I will look into this too. But we'll have to upgrade to 8.3 which is not a problem.

Thank you Reece.

Dianne