Jump to content

Convert Form Values to Object?


TomTees

Recommended Posts

How does everyone take data input from an HTML Form and convert it into an Object in OOP?

 

I am thinking it would be better if user inputs resided in an object so that I could manipulate the data in OOP terms instead of referencing the Form procedurally.

 

 

TomTees

 

Link to comment
https://forums.phpfreaks.com/topic/216616-convert-form-values-to-object/
Share on other sites

Using classes doesn't mean your necessarily using OOP and using OOP doesn't necessarily mean everything has to be an object. Arrays are perfect for storing this type of data.

 

I'm not sure how exactly you plan on manipulating this data, but you'll likely want to pass this into your manipulation object in the form of an array.

 

There are of course complete form components around that do indeed provide access to form values via objects, these objects would still store there data as an array however.

 

It really depends on what your doing exactly. I mean, you could just make a forum object and let it have magic methods to access its internal data structure (a copy of $_POST), but that doesn't really do anything for you.

Using classes doesn't mean your necessarily using OOP and using OOP doesn't necessarily mean everything has to be an object. Arrays are perfect for storing this type of data.

 

I'm not sure how exactly you plan on manipulating this data, but you'll likely want to pass this into your manipulation object in the form of an array.

 

Well, I figured to program more like an OO programmer, I should start off my e-commerce site by taking what a user enters in, say, a Registration Form, and put that into an Object.

 

So I was thinking of having a FormHandler class which would take the form input and place it into an object.  From there, maybe I could pass that object to a FormValidator object to make sure the data is clean.  And from there, maybe I could pass that object to a Registration class to actually register the user...

 

It just seemed cleaner to hurry up and get the Form data into an object?!  :shrug:

 

 

There are of course complete form components around that do indeed provide access to form values via objects, these objects would still store there data as an array however.

 

It really depends on what your doing exactly. I mean, you could just make a forum object and let it have magic methods to access its internal data structure (a copy of $_POST), but that doesn't really do anything for you.

 

See above.

 

I've never programmed in OOP before, and I am trying to program in a semi-sophisticated way.  Stuff that would make the Gang of Four proud of me!  8)

 

(My goal for this weekend is to try and build a simple Registration Module.)

 

 

 

TomTees

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.