TomTees Posted October 23, 2010 Share Posted October 23, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/216616-convert-form-values-to-object/ Share on other sites More sharing options...
trq Posted October 23, 2010 Share Posted October 23, 2010 Form values turn up within either the $_POST or $_GET arrays. I'm not sure why you would need them within an object. Quote Link to comment https://forums.phpfreaks.com/topic/216616-convert-form-values-to-object/#findComment-1125428 Share on other sites More sharing options...
TomTees Posted October 23, 2010 Author Share Posted October 23, 2010 Form values turn up within either the $_POST or $_GET arrays. I'm not sure why you would need them within an object. Because I'm using OOP... TomTees Quote Link to comment https://forums.phpfreaks.com/topic/216616-convert-form-values-to-object/#findComment-1125430 Share on other sites More sharing options...
trq Posted October 23, 2010 Share Posted October 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/216616-convert-form-values-to-object/#findComment-1125432 Share on other sites More sharing options...
PFMaBiSmAd Posted October 23, 2010 Share Posted October 23, 2010 For what it's worth - $post = (object)$_POST; Quote Link to comment https://forums.phpfreaks.com/topic/216616-convert-form-values-to-object/#findComment-1125434 Share on other sites More sharing options...
TomTees Posted October 23, 2010 Author Share Posted October 23, 2010 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?! 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! (My goal for this weekend is to try and build a simple Registration Module.) TomTees Quote Link to comment https://forums.phpfreaks.com/topic/216616-convert-form-values-to-object/#findComment-1125435 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.