HTML Controls

Tequila uses a simple template system (Template power) See templates

To display forms you will normally take traditional HTML techniques and replace some values, however sometimes it can be tricky.

This section refers to tips and tricks in displaying information in HTML controls.

Textboxes, Hidden, TextAreas

This controls are pretty straight forward, just follow this example:

<input name="field_name" type="text" id="field_name" value="{field_value}" />

The field name is normally hard coded in your template, the field_value is set by the PHP code so it should be a placeholder with a normal assignment.

Select, List, Multiple List

This controls uses a collection of options in our HTML templates we simply add a placeholder called:

<select ... >{options_FIELD_NAME}</select>

On the view side, you have many options to display the options:

a) When displaying a VO for editing you can use the view_editor strategy.

$mystrategy->addselect('control_name');

b) When your data uses HTMLOptions (recommended) you can use view_select strategy or it's wrapper function

// THIS HAPPENS IN THE MODEL OR DAOfunction getsomeoptions(){ $mSql = "Select..."; // Use GetData function to retrieve data as HTMLOptions VO return getData($mSql, 'HTMLOptions');}// IN VIEW$options = $this->model->getsomeoptions();$this->addselect('myfieldname', $options);// Function addselect parameters public function addselect($tag, $datasource, $global = false, $postselect = '')

c) When you just want to render a single control and your information is an array you can use the function getSelectOptions

$fieldnames = $this->model->getfieldnames($tabledata[1]);$this->template->assign('options_dskeys', $this->getSelectOptions($fieldnames, $selvalue);

Radio buttons

Radio buttons are little tricky to show with templates specially if you want the options in your template (and not to be "printed"/"echoed" in a cycle).

Let's see an example on how to do this:

<input name="I_IDCATEGORY" type="radio" value="1" {I_IDCATEGORY_1} /><label>dessert</label><input name="I_IDCATEGORY" type="radio" value="2" {I_IDCATEGORY_2} /><label>entree</label><input name="I_IDCATEGORY" type="radio" value="3" {I_IDCATEGORY_3} /><label>main</label>

For each available option we will add a placeholder mixing, option_name + option_value

If you are using the view_editor strategy you just define the field:

$strategy->addoption('I_IDCATEGORY', $this->model->get_I_IDCATEGORY());

On the assignment we will combine the name of the property with it's value to replace just the selected option.

$this->template->assign("I_IDCATEGORY_".$obj->I_IDCATEGORY, 'checked="checked"');

Checkboxes

Checkboxes need a similar trick to the radio buttons one.

On your template:

<input name="I_ACTIVE" type="checkbox" id="I_ACTIVE" value="1" {I_ACTIVE} /> I_ACTIVE

In this case we only add a placeholder using the field name

To assign it using the view_editor strategy:

$strategy->addselect('I_IDCATEGORY', $this->model->get_I_IDCATEGORY());

Using normal template techniques:

$this->template->assign('I_ACTIVE', ($f->val_I_ACTIVE? 'checked="checked"' : ''));

Learn by example.

Tequila generator automates the creation of more than 10 types of controls, including this ones with DB options and fixed options, just generate a valid sample with the control you need to learn!