Re: HTML_QuickForm_Date display before 1969
| From: | Justin Patrin | Date: | Tue, 18 Jan 2005 18:58:23 +0000 |
| Subject: | Re: HTML_QuickForm_Date display before 1969 | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-17000@lists.php.net to get a copy of this message | ||
On Tue, 18 Jan 2005 10:20:38 -0600, Sarah Gray <sarah@fabled.net> wrote:
> Thanks to you and Huy (and Joseph and Justin).
> This did in fact solve my problem -- I went from sensing what the problem was
> last night before bed, to getting it sorted based on your code sample this
> morning.
>
> I left the element created in preGenerateForm because that seemed cleaner than
> removing it and re-adding it.
>
> function preGenerateForm(){
> $options = array('minYear'=>1924,
> 'maxYear'=>1990,
> 'addEmptyOption'=>true,
> 'format'=>'dMY');
>
> $QF_date = new HTML_QuickForm_date('DOB', 'Date of Birth',$options);
> $this->preDefElements['DOB'] = $QF_date;
> }
>
> Then in postGenerateForm I wrote this:
>
> $dArr = explode('-', $this->DOB);
> $DOBArr =
> array("d"=>$dArr[2],"M"=>$dArr[1],"Y"=>$dArr[0]);
> $form->setDefaults(array('DOB'=>$DOBArr));
>
> And, voila!
>
> Thanks again for everyone's help. It didn't seem right that just because
> strtotime couldn't handle it that it couldn't be done.
You may also want to consider upgrading. THere have been lots of bug
fixes and feature additions since 0.9.0. Also, the online docs won't
be of much help with that version. :-|
There are scripts in CVS to update your ini and class files, although
I have not tested them recently.
http://cvs.php.net/co.php/pear/DB_DataObject_FormBuilder/fix0.9.0Files.php?r=1.3
>
> Sarah
>
> Joseph Blythe wrote:
>
> > Hi,
> >
> > We ran into simular troubles when retrieving mySQL timestamps and trying to
> > use HTML_QuickForm::setDefaults the default date element is a group so
> > instead of doing:
> >
> > $qf->setDefaults('date'=>'1940-02-13');
> >
> > format it as an array like (you will need to convert the timestamp first)
> >
> > $qf->setDefaults('date'=> array('Y'=>'1940',
> > 'M'=>'02', 'd'=>'13'));
> >
> > Regards,
> >
> > Huy and Joseph (hehe took two of us to work that out)
> >
> > -----Original Message-----
> > From: Sarah Gray [mailto:sarah@fabled.net]
> > Sent: Tuesday, 18 January 2005 3:16 PM
> > To: Pear
> > Subject: Re: [PEAR] HTML_QuickForm_Date display before 1969
> >
> > Actually, am I just running into this issue because PHP date functions are
> > only
> > guaranteed to work after Jan 1, 1970? And so regardless of where I use them,
> > like
> > in my HTML_QuickForm_Date elements, I can't get an earlier date? This didn't
> > strike me as obvious until a few minutes ago when I was thinking about the
> > limits
> > of PHP date, and then I thought 'of course! This is probably the reason my
> > dropdowns balk when going earlier than 1969 (12-31), and I was looking for
> > something more complex that had to do with FormBuilder'.
> >
> > If I'm right here, to generate date dropdowns for dates prior to 1970 (ie,
> > birthdays of older people), is there anything you'd recommend other than
> > creating
> > individual elements in a group in the form and building a date element
> > manually?
> >
> > Thanks,
> > Sarah
> >
> > Sarah Gray wrote:
> >
> > > Hi,
> > >
> > > >
> > > > You shouldn't have to do this. Put this element in
> > > > $this->fb_preDefElement['DOB'] in preGenerateForm instead of
> > > > removing
> > > > and recreating in postGenerateForm. This will also remove the need for
> > > > the setValue call below, which could easily break as FB uses
> > > > setDefaults. Try this and see if the problem is fixed.
> > >
> > > Thanks for the suggestion -- it is definitely a cleaner way to think about
> > it,
> > > and I removed the calls in postGenerateForm, replacing them with this:
> > >
> > > function preGenerateForm(){
> > > $options = array('minYear'=>1924,
> > > 'maxYear'=>1990,
> > > 'addEmptyOption'=>true,
> > > 'format'=>'dMY');
> > >
> > > $QF_date = new HTML_QuickForm_date('DOB', 'Date of
> > > Birth',$options);
> > > $this->preDefElements['DOB'] = $QF_date;
> > > }
> > >
> > > [I'm using an earlier version of FormBuilder, before the fb_ prefixes
> > (version
> > > 0.9.0).]
> > > It does create the element as desired, with the proper minYear and maxYear
> > --
> > > but the behaviour is still the same -- not displaying dates before 1969
> > but
> > > displaying them corerctly after 1969. Any thoughts? An obscure setting
> > > somewhere? Still messed-up syntax?
> > >
> > > Thanks.
> > >
> > > >
> > > >
> > > > > $options = array('minYear'=>1924,
> > > > > 'maxYear'=>1990,
> > > > > 'addEmptyOption'=>true,
> > > > > 'format'=>'dMY');
> > > > >
> > > > > $QF_date = new HTML_QuickForm_date('DOB', 'Date of
> > > > > Birth',$options);
> > > > > $QF_date->setValue($this->DOB); // the date from the db, formatted
> > > > > 1969-02-14
> > > > > $form->addElement($QF_date);
> > > > > }
> > > > >
> > > > > Thanks -- Sarah
> > > > >
> > > >
> > > > --
> > > > Justin Patrin
> > >
--
Justin Patrin