For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > March 2005 > Re: [PEAR] QuickForm: How do I setup the Date element values?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PEAR] QuickForm: How do I setup the Date element values?
Justin Patrin

2005-03-14, 3:58 pm

On Mon, 14 Mar 2005 07:05:45 -0800, Mark Steudel <msteudel@panicware.com> wrote:
> I have the following date element:
>
> $form->addElement('date', 'orderdate', 'Order Date:',
> array('format'=>'Y-m-d', 'minYear'=>2010, 'maxYear'=>2001));
>
> I know that this creates an array, orderdate[Y,m,d], it defaults to
> 2010-1-1, how do I pass an array back to the date element to set the values
> to something else (e.g. if I'm using the form to edit pre-existing data)
>
> I tried the following:
>
> // separate date in format 2004-01-01
> $explodeDate = explode ( "-", $objData->orderdate );
>
> // construct new array
> $existDate = array("Y"=> $explodeDate[0], "m" => $explodeDate[1], "d" =>
> $explodeDay[2]);
>
> // try and change the value of the date element
> $form->addElement('date', 'orderdate', 'Order Date:',
> array('format'=>'Y-m-d', 'minYear'=>2010, 'maxYear'=>2001, 'value' =>
> $existDate));
>
> But that didn't work.
>


Best way is to use setDefaults.

$form->setDefaults(array('orderdate' => $existDate));

You can also use that to set multiple values at once.

--
Justin Patrin
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com