Re: DB_DataObject_FormBuilder - hiding linked values

From: Date: Thu, 21 Jun 2007 15:37:53 +0000
Subject: Re: DB_DataObject_FormBuilder - hiding linked values
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-27532@lists.php.net to get a copy of this message
On 6/21/07, Erik Lemcke <ELemcke@wwf.nl> wrote:
I have a little problem with a form I'm building with formbuilder. Besides the data entered in the form, I want to store which user filled the form. For that I have a table users, linked to the table that the form is generated (called dc_document) for (so in that table, there is a field creat_user_id) Formbuilder makes a nice select box, so you can select the username (from the linked users table) Since I use auth to authenticate, I already know the userid of the user that is filling the form, so I can set the value when I create the form like in this small example: //create the dataobject $document = DB_DataObject::factory('Dc_document'); //set the user id $document->user_id = $user_id; //create the form $fg = DB_DataObject_FormBuilder::create($document); $form = $fg->getForm('index.php'); if ($form->validate()) { $form->process(array(&$fg, 'processForm'), false); } else { echo $form->toHtml()); } So the user select box is now set to the currently logged in user. That's great, but I don't want the user to be able to alter that value. I've tried doing that by making the select box hidden, like I would do with a input box, but that didn't work (since usually there's no point in making a html select box when it's hidden) So there's possible a better way to store the user id in the database while not showing it in the form, I just can't find out how to do it. Any ideas?
A few thoughts. You could always just freeze the user select field when the user is logged in so that they can see it but not edit it. Couple this with prepareLinkedDataObject to make the field only show the logged in user (to stop pointless record fetching) and you have a decent solution. You could also just not put the user field in the userEditableFields / fieldsToRender and set it and update() yourself after the form has been processed. -- Justin Patrin

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