Re: QuickForm php warning using DB_DataObject_FormBuilder

From: Date: Mon, 27 Jun 2005 20:32:22 +0000
Subject: Re: QuickForm php warning using DB_DataObject_FormBuilder
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19783@lists.php.net to get a copy of this message
On 6/27/05, Dan C <dankind@gmail.com> wrote: > This is exactly what I just did before I checked my email, and you're > totally correct. It is a date field I changed to a string (hidden > field). I'd like to have certain fields (date_updated, date_added, > etc) that get filled in automatically when the form is submitted. > > Currently I'm doing it like this but perhaps this is wrong: > preGenerateForm() > - sets the date fields to hidden > preProcessForm > - assigns the date field values using php date() function > > Is there a better/more proper way to do this? > Yes. This data does not belong in the form. I believe I've explained before that these are backend data operations not frontend actions (i.e. these fields are not set by the user in the form so they should not be included on it). Make these fields not display at all (don't put them in fieldsToRender). Then override the insert and update functions in your DO to set them appropriately. i.e. class My_DO extends DB_DataObject { //... function insert() { require_once('DB/DataObject/Cast.php'); $this->date_added =& DB_DataObject_Cast::sql('NOW()'); //or you could use date('Y-m-d H:i:s'); return parent::insert(); } function update($do = false) { require_once('DB/DataObject/Cast.php'); $this->date_updated =& DB_DataObject_Cast::sql('NOW()'); return parent::update($do); } } > > On 6/27/05, Justin Patrin <papercrane@gmail.com> wrote: > > On 6/27/05, Dan C <dankind@gmail.com> wrote: > > > Hi All, > > > > > > I'm getting this error when using the $form->toHtml method of quickForm: > > > > > > Warning: htmlspecialchars() expects parameter 1 to be string, array > > > given in /usr/local/lib/php/HTML/Common.php on line 140 > > > > > > The form was created using DB_DataObject_Formbuilder, and this is only > > > happening in one specific instance, otherwise FormBuilder works great.. > > > > > > Now... I'm not sure how to backstep and find out exactly which method > > > is calling that. Line 140 is inside the _getAttrString() method, which > > > seems to only be called by the getAttributes() method in Common.php. > > > > > > Running: > > > /usr/local/lib/php/HTML/QuickForm$ grep getAttr * > > > > > > I get 34 results in different files... can anyone recommend a better > > > way to debug this so I can find out what's causing this error? > > > > > > > Well you can always output the fill attr string in that function. Add > > an if(!is_string()) around your echo and see what the other attributes > > are. Are you perhaps replacing a date element with a text element? > > This could easily happen because of that as the defaults FormBuilder > > sets are for the date element. > > > > -- > > Justin Patrin > > > -- Justin Patrin

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