Ferreteria/v2/usage/forms/displaying: Difference between revisions

From Woozle Writes Code
< Ferreteria‎ | v2‎ | usage‎ | forms
Jump to navigation Jump to search
(template example)
m (8 revisions imported: moving this project here)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
==displaying a form==
==displaying a form==
See {{vbzcart/code|dropins/orders/order.php#L1178|order.php AdminPage_basic()}} for a working example of a full-page form, and {{vbzcart/code|dropins/orders/order.php#L1313|order.php PageTemplate()}} for building a template.
See {{l/vc/code|dropins/orders/order.php#L1178|order.php AdminPage_basic()}} for a working example of a full-page form, and {{l/vc/code|dropins/orders/order.php#L1313|order.php PageTemplate()}} for building a template.


===template example===
===template example===
<php>
<source lang=php>
     private $tpPage;
     private $tpPage;
     protected function PageTemplate() {
     protected function PageTemplate() {
Line 27: Line 27:
}
}
return $this->tpPage;
return $this->tpPage;
</php>
</source>
===without templates===
===without templates===
It can also be done without templates by retrieving the control and asking it to render itself:<php>
It can also be done without templates by retrieving the control and asking it to render itself:<source lang=php>
    $oForm = $this->EditForm();  // retrieve the form object (build it if needed)
    $oForm = $this->EditForm();  // retrieve the form object (build it if needed)
    $oForm->LoadRecord();        // copy values from {memory image of record} to {form fields}
    $oForm->LoadRecord();        // copy values from {memory image of record} to {form fields}
Line 36: Line 36:
    $ftAddr = $oForm->ControlObject('ID_Addr')->Render($doEdit);
    $ftAddr = $oForm->ControlObject('ID_Addr')->Render($doEdit);
    $ftName = $oForm->ControlObject('ID_Name')->Render($doEdit);
    $ftName = $oForm->ControlObject('ID_Name')->Render($doEdit);
</php>
</source>
...(and so on), then manually plugging the rendered controls into the desired output format:<php>
...(and so on), then manually plugging the rendered controls into the desired output format:<source lang=php>
$out .= <<<__END__
$out .= <<<__END__
<table>
<table>
Line 49: Line 49:
</table>
</table>
__END__;
__END__;
</php>
</source>
...but note that calling LoadRecord() causes the Field objects to return TRUE from IsChanged() if the loaded value is non-NULL. This overrides POST data in $oForm->Save(), so presumably you'll need to build the update query manually or else clear the form fields somehow (currently not supported, but maybe it should be).
...but note that calling LoadRecord() causes the Field objects to return TRUE from IsChanged() if the loaded value is non-NULL. This overrides POST data in $oForm->Save(), so presumably you'll need to build the update query manually or else clear the form fields somehow (currently not supported, but maybe it should be).

Latest revision as of 16:46, 22 May 2022

displaying a form

See Template:L/vc/code for a working example of a full-page form, and Template:L/vc/code for building a template.

template example

    private $tpPage;
    protected function PageTemplate() {
	if (empty($this->tpPage)) {
	    $sTplt = <<<__END__
<table>
  <tr><td align=right><b>ID</b>:</td><td>[[ID]]</td></tr>
  <tr><td align=right><b>Status</b>:</td><td>[[Status]]</td></tr>
  <tr><td align=right><b>Cart</b>:</td><td>[[Cart]]</td></tr>
</php>...<php>
  <tr><td align=right><b>Ship $ quoted</b>:</td><td>[[QuoShip]]</td></tr>
  <tr><td align=right><b>Final $ quoted</b>:</td><tr>[[QuoFinal]]</td></tr>
  <tr><td align=center colspan=2>
    <table>
    [[AmtMerch]]
    [[BalBtnsLine]]
    [[RecalcLine]]
    </table>
  </td></tr>
</table>
__END__;
	    $this->tpPage = new fcTemplate_array('[[',']]',$sTplt);
	}
	return $this->tpPage;

without templates

It can also be done without templates by retrieving the control and asking it to render itself:

	    $oForm = $this->EditForm();   // retrieve the form object (build it if needed)
	    $oForm->LoadRecord();         // copy values from {memory image of record} to {form fields}
	    $ftTag	= $oForm->ControlObject('Name')->Render($doEdit);
	    $ftCust	= $oForm->ControlObject('ID_Cust')->Render($doEdit);
	    $ftAddr	= $oForm->ControlObject('ID_Addr')->Render($doEdit);
	    $ftName	= $oForm->ControlObject('ID_Name')->Render($doEdit);

...(and so on), then manually plugging the rendered controls into the desired output format:

	$out .= <<<__END__
<table>
  <tr><td align=right><b>ID</b>:</td><td>$id</td></tr>
  <tr><td align=right><b>Tag</b>:</td><td>$ftTag</td></tr>
  <tr><td align=right><b>Status</b>:</td><td>$ftStatus</td></tr>
  <tr><td align=right><b>Customer</b>:</td><td>$ftCust</td></tr>
  <tr><td align=right><b>Address</b>:</td><td>$ftAddr</td></tr>
  <tr><td align=right><b>Name</b>:</td><td>$ftName</td></tr>
...
</table>
__END__;

...but note that calling LoadRecord() causes the Field objects to return TRUE from IsChanged() if the loaded value is non-NULL. This overrides POST data in $oForm->Save(), so presumably you'll need to build the update query manually or else clear the form fields somehow (currently not supported, but maybe it should be).