Re: DO and QF populating select options

From: Date: Mon, 17 Oct 2005 01:40:11 +0000
Subject: Re: DO and QF populating select options
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-21509@lists.php.net to get a copy of this message
On 10/16/05, Prue <prue@clipmagic.com.au> wrote: > One other thing with FB.... > The date fields default to 0 which throws and error in Windows. By using QF > on its own, I was able to format the default date to today. How can I fix > this in FB? Where is an error thrown? FB doesn't default anything to anything. I've always seen the date fields default to today in a new record form. I also always run my server on Linux. If you're running your server on Windows and get an error please let me know exactly what it is and where it happens. Please include all relevant code. > > Regards > Prue > > -----Original Message----- > From: Prue [mailto:prue@clipmagic.com.au] > Sent: Monday, 17 October 2005 7:05 AM > To: 'papercrane@reversefold.com' > Subject: RE: [PEAR] DO and QF populating select options > > > Thanks Justin, > > I've tried (and love FB) however I have a problem with that too which may be > related to the issues I'm having here. I'm using Smarty templates and when > I use FB, writing {$form.header.headertxt} or {$form.name.label}.in the > templates, as it says to do in the manual (and I have read QF, DBDO, FB, > Smarty manuals extensively and trawled the internet for tutorials as well as > this mailing list) gives "Fatal error: Cannot use string offset as an array > in..." in where? > > In the example I'm trying without FB, I have: > > <snip> > $person = DB_DataObject::factory(person ); > $person ->selectAdd(); > $person ->selectAdd('person_id'); > $person ->selectAdd('name'); > $person ->orderBy('name'); > $person ->find(); > while ($person -> fetch()) { > /* store the results in an array */ > $options[] = clone($person ); > echo "got {$person->person_id},{$person->name}<br />"; > /* this correctly outputs the required result to the screen */ } > > $form->addElement('select', 'person _id', 'Person', > array($options['person > _id']=>$options['person']) ); And....what exactly do you think is supposed to happen here. Up above you're adding each person DO to the end of the $options array. This gives you a number indexed array of DOs. For the 'options' parameter you're sending array($options['person_id']=>$options['person']). Since $options is a numbered array these keyed indices don't exist and you actually end up with array('' => ''). Nothing you do here is going to make QF read your array. It doesn't understand DB_DOs. The select element expects an array in the format of: array('value' => 'display', 'value2' => 'display2', etc...) Now, you *could* make your options array be in this format by doing something like: $options[$person->person_id] = $person->name; In your look instead of the $options[] line. However, this isn't a good way to do it since it will create a large array which you're about to use. The better way is to create the element before the loop and add an option to it for every person. before the loop: $el =& HTML_QuickForm::createElement('select', 'person _id', 'Person'); in the loop: $el->addOption($person->name, $person->person_id); after the loop: $form->addElement($el); In the future, please read the docs more carefully and try to understand what you're doing. > /* this results in an empty select box */ > </snip> > > A dump of $options shows that the fields are two levels down in the array, > eg $options[0][club_id] gives me the first row, which is as it should be > however I don't know how to access that from within the QF element > description. > > If I can fix this, ie get the key=>data as the first level in the array, I > will happily go back to using the FB/Smarty combination. > > Any ideas? > > Regards > Prue > > > > -----Original Message----- > From: Justin Patrin [mailto:papercrane@gmail.com] > Sent: Monday, 17 October 2005 3:11 AM > To: prue@clipmagic.com.au > Cc: pear-general@lists.php.net > Subject: Re: [PEAR] DO and QF populating select options > > > On 10/16/05, Prue <prue@clipmagic.com.au> wrote: > > Hi > > > > This should be easy - everything I've read says so, but I cant get it > > working. I have a DataObject that references another table via a > > foreign key. The relationships are set up in links.ini. I can > > factory the second table and retrieve the query, eg id and name which > > will be the select options, but I cant work out how to then insert the > > result into the QF select element options. > > > > Sorry this is such a dumb question. I've read, looked, tried > > everything I can think of and I know it shouldn't be difficult but... > > > > Look at the HTML_QF manual for how to add options to a select. Then loop > over your DO records and add an option for each record. > > BTW, DB_DO_FB would do all this automatically for you. > > -- > Justin Patrin > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- Justin Patrin

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