Re: Weird $_GET behaviour with DB_DataObject_FormBuilder
| From: | Markus Wolff | Date: | Sun, 11 Jul 2004 00:26:40 +0000 |
| Subject: | Re: Weird $_GET behaviour with DB_DataObject_FormBuilder | ||
| References: | 1 2 3 4 5 6 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-13623@lists.php.net to get a copy of this message | ||
Sarah Gray wrote:
You are so right. I don't *understand* why these two things would be related-- ie, why does the behaviour misfire when using the $_GET value, but not misfire when using any other variable? It would seem to me that if the lack of the hidden field stopped the updates when using $_GET, it would stop the updates when using other variables as well. But you nailed it. As ever, thanks.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 :-))