Re: Weird $_GET behaviour with DB_DataObject_FormBuilder

From: Date: Sun, 11 Jul 2004 11:38:00 +0000
Subject: Re: Weird $_GET behaviour with DB_DataObject_FormBuilder
References: 1 2 3 4 5 6 7  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-13633@lists.php.net to get a copy of this message
Hi Markus, I get it now - Thanks! ;) Once you explained it like this, it makes perfect sense (and is one of those things you think 'why didn't I see that earlier'!). In my debugging process, I was clearly overlooking the fact that the form submits (and thus loses it's $_GET), and I hadn't realized that the hidden id field was not in the form, since I hadn't defined it in preDefOrder && fieldsToRender. Somehow I was thinking of those arrays as affecting the visuality of the form but not removing the hidden elements. The other project of mine that I referenced (using a later version of FormBuilder and not displaying this problem) has less complex forms, and thus I hadn't been setting those arrays, so of course the hidden field was still there and things worked great. Shows how you can get sidetracked when you think you know what the problem is, and then miss the problem! Anyway, I definitely learned a few things -- & broadened my understanding of FormBuilder and QuickForm to boot. ;) Thanks much, Sarah > > > Hi Sarah, > > I've just read the thread and I can offer another alternative that might > ease understanding of the issue. > > To get the form object, you're just using: > > $form =& $fb->getForm(); > > ...or something very similar. The important thing is, you don't pass any > parameter to getForm(). If you don't, the QuickForm default action will > be used, which is $_SERVER['PHP_SELF']. > Now, the PHP_SELF value only contains the script path, but not its GET > parameters. Thus, things are going like this: > > 1. You call the script with an URL like "myscript.php?id=3" > 2. You initialize your DataObject with $_GET['id']. > 3. The data is loaded correctly, the form is displayed, but > the form action attribute is simply "myscript.php", without > the GET-parameter! > 4. You alter your data and submit > 5. The page is reloaded, without the GET parameter. The DataObject > remains empty because the data cannot be loaded. > 6. The form values are put into the DataObject. They do not contain > the ID because there was no hidden field in the form containing > its value and there is no GET parameter anymore. > 7. Because of 5. and 6. an INSERT is performed, as there is no ID :-) > > > To prevent this, either use hidden fields as Justin suggested, or do > something like this for getting the form: > > $form =& $fb->getForm($_SERVER['REQUEST_URI']); > > Note that the REQUEST_URI value might not be set in all possible > environments (like, for example, Microsoft IIS* with PHP via CGI). > > Regards, > Markus > > (* IIS = Instant Intrusion Server :-))

« previous php.pear.general (#13633) next »