Quickform SetDefaults
| From: | Barry Steele | Date: | Mon, 05 Jan 2004 11:02:31 +0000 |
| Subject: | Quickform SetDefaults | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-9963@lists.php.net to get a copy of this message | ||
hi,
I'm having an issue with setting default values in QFC page.
I have a single form for entering and updating data. The form uses
textboxes, radiobuttons, checkboxes etc - the radio buttons and
checkboxes are built from reference tables.
I have built a few functions to set the relevant values in the fields
and these work fine for the first record - be it a 'new' or 'edit'
(values retrieved from the database).
BUT if the user has entered any data, the values that were in the form
are always displayed in the form.
// Set the values of the Incident Form
function setValues($incident=null)
{
// Clear all remnant REQUEST values
$this->controller->container(true);
// if $incident is set
if ($incident)
{
//Var_Dump::display($incident->incident->toArray());
$incident->incident->getLinks();
// direct values
$DefaultVals=$incident->incident->toArray();
list($Date['Y'],$Date['M'],$Date['d'])=split('[./-]',$DefaultVals['Date']);
$this->setDefaults($DefaultVals);
// Name - need to split the first and surnames
$Name = $DefaultVals['Name'];
$nameFld = &$this->getElement('incName');
$nameFld->setValue($Name);
// OR - change the form to conform == better idea
// Set the date
$incDateFLD = &$this->getElement('Date');
$incDateFLD->setValue($Date);
// DOB
$vicDOBFLD= &$this->getElement('DOB');
//echo "DOB = ".$DefaultVals['DOB']."<br>";
list($DOB['Y'],$DOB['M'],$DOB['d'])=split('[./-]',$DefaultVals['DOB']);
//Var_Dump::display($DOB);
$vicDOBFLD->setValue($DOB);
$incTypeFLD= &$this->getElement('Type');
$incTypeFLD->setValue($TypeVal);
// Set values for linked Tables
// Incident Type
$this->setCheckBoxVals('Type','IncidentType',$incident,'TypeID','Expl');
// Contributing Factors
$this->setCheckBoxVals('ContFact','IncFactors',$incident,'ContFactID','ContExpl');
// Injury Details
$this->setCheckBoxVals('InjuryNature','Injury',$incident,'InjuryNatureID','InjuryExpl');
//Body Part
$this->setCheckBoxVals('BodyPart','Body',$incident,'BodyPartID','Explanation');
// Referral
$this->setCheckBoxVals('ReferralID','IncReferral',$incident,'ReferralID','RefExpl');
// Other Services
$this->setCheckBoxVals('ServiceID','IncService',$incident,'ServiceID','ServExpl');
// Treating Person
$this->setCheckBoxVals('TreatingID','IncTreating',$incident,'TreatingID','TreatExpl');
return true;
}
else
{
return true;
}
}
As you see I set the data after the fields are set. Essentially what I
need to do is to try to clear any data that was held in the container -
I thought "$this->controller->container(true);" - would do it.
Any thoughts?
Barry Steele
hpfm solutions pty ltd
mob: 0413947980
fax: 0299817727
mailto:: barry@hpfm.biz