Ferreteria/v2/usage/forms/creating

From Woozle Writes Code
< Ferreteria‎ | v2‎ | usage‎ | forms
Revision as of 21:28, 21 November 2015 by htyp>Woozle (→‎Examples: default field value)
Jump to navigation Jump to search

How to create a form for editing record-based data:

from Template:Vbzcart/code (function PageForm()): <php> $oForm = new fcForm_DB($this->Table()->ActionKey(),$this); $oField = new fcFormField_<type>($oForm,'<field name>'); $oCtrl = new fcFormControl_HTML[_<type>]($oForm,$oField,array([HTML attributes]); </php> The first line creates a Form object, the next line creates a Field, and the third line assigns a Control to the Field. Adding additional fields and controls follows the format of the last 2 lines.

Fields and Controls

Field types (Template:Ferreteria/code):

  • fcFormField_Text
  • fcFormField_Num
  • fcFormField_Time
    • ->Format(<date format>)

Control types (Template:Ferreteria/code):

  • fcFormControl_HTML - generic single-line text-editing field
  • fcFormControl_HTML_TextArea - multiline text
    • attributes: rows, cols
  • fcFormControl_HTML_Hidden - hidden values
  • fcFormControl_HTML_DropDown - drop-down chooser
    • ->Records(<dataset>);
  • fcFormControl_HTML_CheckBox - checkbox

Examples

General: <php>// set a default value for new records $oField->SetDefaultNative($this->TitleID());</php> Timestamp: <php> $oField = new fcFormField_Time($oForm,'WhenEnt'); $oCtrl = new fcFormControl_HTML($oForm,$oField,array('size'=>10)); $oField->Format('m/Y'); </php> This sets the format of the Control for the "WhenEnt" field based on the parameter string used by the PHP date() function – in this case, just the month (2 digits) and year (4 digits) are displayed.

Dropdown selector: <php> $oField = new fcFormField_Num($oForm,'ID_Place'); $oCtrl = new fcFormControl_HTML_DropDown($oForm,$oField,array()); $oCtrl->Records($this->PlaceTable()->GetData_forDropDown()); </php>

TextArea: <php>$oCtrl = new fcFormControl_HTML_TextArea($oForm,$oField,array('rows'=>3,'cols'=>60));</php>

Other Elements

See "displaying" for the care and feeding of form templates.