Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 22nd, 2003, 06:21 PM
Registered User
 
Join Date: Sep 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default passing a php oop object in a form

Hi all, I hope someone can help me wade through the oop mess I have entangled myself in.

I have a situation where depending upon which contract is selected there could be a variable number of records in the database associated with that contract. I am setting up a form where someone could add, subtract, and/or modify the information for the record(s) for the specific contract.

Supposedly to make my life easier I decided to dabble with oop. I created a class called contracted_fields (field as in farm field not database field). The member I am primarily working with is the approvedField member which is an array of parameters (id, size, name, etc).

I would like to have a couple of different methods for this class which either add an additional array value to the approvedField member or delete an array value.

When I was just using functions I would have all my values I wanted to keep printed out as hidden input fields and then delete out the array and add in all my post variables. Now that I am wanting to do this the oop way, can I pass my object through a form using the post method and then call the different methods I need on the other post variables from the form.

I think I confused myself just writing this. I hope one of you guys or gals can understand what I am trying to do and help.

I'm running out of time and my only other option is to include a bunch of php code within my html code and I really want to separate my logic from my presentation.

Thanks.

Julie

 
Old December 22nd, 2003, 09:14 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I think I would be able to get my mind around what you're trying to do a little more easily if you could post some code of what you're trying to do. This would allow one of us to better see if you're expected output is what will actually result... and if you have a clear understanding of how a class is supposed to function in PHP.

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old December 24th, 2003, 07:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can't pass a PHP object through an HTML form. HTML can submit text or binary files. If you have an object already in existence that you'd like to persist across multiple pages, store it in a session variable.

You can also serialize the object into a string and unserialize it back into an object by using hidden form fields, but this serialization/unserialization process is how PHP would store and retrieve the object in your session data file anyway...

One warning, though -- if you store an object in a session var, the object's class must be defined BEFORE you call session_start() so that PHP knows what the object's name and structure are:

<?php // MyClass.php

class MyClass
{
   var $foo;
   function MyClass() { $this->foo = "Hello, world."; }
   function out() { echo $this->foo; }
}
?>

<?php // your_script.php

require('myClass.php'); // parse class definition
session_start(); // BEFORE session_start()
...

?>


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing unique record from form to form Baconant Beginning VB 6 1 January 2nd, 2008 06:20 PM
Passing FORM to FORM to PHP AV1611 PHP Databases 1 August 17th, 2005 03:32 PM
passing value from Php to PHP page baby PHP How-To 3 March 31st, 2005 02:13 AM
Passing Variables from PHP to PHP brian3166 PHP How-To 4 January 31st, 2005 12:44 AM
Passing Value from main form to Popup Form smartgir Access VBA 0 February 26th, 2004 06:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.