Another FormBuilder question
| From: | James Stewart | Date: | Tue, 15 Feb 2005 21:15:58 +0000 |
| Subject: | Another FormBuilder question | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-17539@lists.php.net to get a copy of this message | ||
I've just been reworking some of the formbuilder code I was working on and asking questions about a couple of weeks ago and have run into a problem. I know I've encountered it before, but I can't remember how I got around it, which has been driving me crazy...
I'm using the same function to build my form whether it's for editing a user or creating a new one. My code looks like (with relevant input validation elsewhere):
$data = DB_DataObject::factory('users');
if (!empty($_GET['id'])) {
// I've tested and this is only happening when it ought to be
$data->get($_GET['id']);
}
$ebuild =& DB_DataObject_FormBuilder::create($data);
$form = $ebuild->getForm();
if ($form->validate()) {
$form->process(array(&$ebuild,'processForm'), false);
return;
}
// Go on to output form
and so on.
The error I'm seeing is that when I create a new user the DataObject tries to insert it using an UPDATE query. ie:
dataobjects_users: QUERY: UPDATE users SET user_name = 'James Stewart' , etc, etc, etc WHERE users.user_id = IS NULL
Obviously this isn't working, but I can't remember why it's using UPDATE instead of INSERT in this instance.
thanks. James.