RE: [PEAR] display of submitted values and an empty form on the same page using Quickform
| From: | Justin Adie | Date: | Thu, 03 Aug 2006 15:56:35 +0000 |
| Subject: | RE: [PEAR] display of submitted values and an empty form on the same page using Quickform | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-24822@lists.php.net to get a copy of this message | ||
i don't think that clone() will do the trick here. php (with clone and =)
seems to pass a copy of the "done" object thus $newerform will be frozen as
per $newform
solutions:
try this for a true copy at a point in time:
$newerform = unserialize(serialize($newform));
or iterate over the elements of $newerform and unfreeze them (you have to do
this to set the values anyway - the below is a kludge, of course)):
<<SNIP>>
$elements = $newerform->getSubmitValues();
foreach($elements as $element=>$value):
$elem =& $newerform->getElement($element);
if (method_exists($elem,"setValue")):
$elem->setValue("");
endif;
if (method_exists($elem,"unfreeze")):
$elem->unfreeze();
endif;
endforeach;
<<SNIP>>
-----Original Message-----
From: Justin Patrin [mailto:papercrane@gmail.com]
Sent: 03 August 2006 16:19
To: Bjoern Mittelsdorf
Cc: pear-general@lists.php.net
Subject: Re: [PEAR] display of submitted values and an empty form on the
same page using Quickform
On 8/3/06, Bjoern Mittelsdorf <mittelsdorf@zpid.de> wrote:
> Thanks in advance Justin.
>
> > setDefaults won't work as the values in the request will override
> > the defaults. I would suggest making a copy of the form object
> > before you freeze it, set the internal var with the submitted values
> > to null (sorry, don't remember its name), and calling one of the
> > functions which re-sets the values of elements (such as setDefaults()).
>
> Copying the object sounds better indeed. But ...
>
> if ( ( isset( $_REQUEST['manual'] ) ) && ( $newform->validate() ) ) {
> $newer_form = $newform ;
Try using clone() here.
> $newform->removeElement( 'manual', TRUE ) ;
> $newform->removeElement( '2)', TRUE ) ;
>
> $newform->freeze() ;
> $newform->addElement( 'static', '1)' , babel(
> "Success") ) ;
> $newform->display() ;
> $newer_form->display() ;
> $newform->process( 'process_manual' , FALSE ) ;
> }
>
> When I use this code, both newform and newer_form are frozen, though
> the add and remove actions are only applied to newform. So I am pretty
> sure that I have two different obejcts not just two references to the
> same object.
>
> Why does $newform->freeze() freeze both objects ?
>
> Have a nice day.
>
> --
> ZPID - Zentrum für Psychologische Information und Dokumentation
> Dipl. Psych. Björn Mittelsdorf Fon: +49(0)651-201-2867
> Projekt PsychData Fax: +49(0)651-201-2604
> Universität Trier E-Mail: mittelsdorf@zpid.de
> 54286 Trier http://www.zpid.de/
>
> --
> PEAR General Mailing List (http://pear.php.net/) To unsubscribe,
> visit: http://www.php.net/unsub.php
>
>
--
Justin Patrin
--
PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php