Knowledge Base

How to replace form fields

No comment
on Wednesday 22 August 2018
comments: 0

TEXT FIELD

Before:
function form_text($form_name, $form_size, $form_value, $form_maxlength = FALSE, $form_class = "tbox form-control", $form_readonly = "", $form_tooltip = "", $form_js = "") {
...
	return "\n<input class='".$form_class."' type="text">";
}
Now:
function text($name, $value = '', $maxlength = 80, $options= array()) 
{
...
	return "<input type='".$type."' name="{$name}" value="{$value}">get_attributes($options, $name)." />";
}
replacing:
$f->form_text($pname."_title", "40", $tp->toHTML($fi["title"]), "200", "form-control")
$frm->text($pname."_title", $tp->toHTML($fi["title"]),  "200", 'size=40&class=form-control')
So: 1. rename method name 2. delete 2rd parameter (4th becames 3rd) 3. set former size parameter like size=99 as 4th parameter Options: - if parameter class is not defined, class tbox is used - if bootstrap 3 (not 4) is used, class form-control is used NOTE for me: ALWAYS set class, not let it for core - selectize script is used if you use options 'id' and 'selectize' (then class is emptied) - option 'type' is available (only email, otherwise has value text) - option 'typehead' with value 'users' is marked as removed soon Example with placeholder:
$frm->text($pname."_googlemap",  $tp->toHTML($fi["googlemap"]), "200", "size=40&class=form-control&placeholder=".CUP_INFO_ADDRESS)

Textarea

Before;
function form_textarea($form_name, $form_columns, $form_rows, $form_value, $form_js = "", $form_style = "", $form_wrap = "", $form_readonly = "", $form_tooltip = "") {
...
		return "\n<textarea class="tbox form-control">".$form_value."</textarea>";
Now:
function textarea($name, $value, $rows = 10, $cols = 80, $options = array(), $counter = false) {
...
		return "<textarea>get_attributes($options, $name).">{$value}</textarea>".(false !== $counter ? $this->hidden('__'.$name.'autoheight_opt', $counter) : '');
So: - swap 4th and 2nd parameters - everything else move to options - set 6th parameter as true Example:
$frm->form_textarea($pname."_info", "10", "20", $tp->toHTML($fi["info"]), "200", "form-control")
$frm->text($pname."_googlemap",  $tp->toHTML($fi["googlemap"]), "200", "size=40&class=form-control&placeholder=".CUP_INFO_ADDRESS)

Open form

$frm->form-open("post", e_SELF, $pname."_form", "", " class='form-horizontal'")
- rename method - move form name as first parameter - replace 3rd with NULL (in this case e_REQUEST_URI is used)
$frm->open($pname."_form",'post', null, array('class'=>'form-horizontal'))

Checkbox

function form_checkbox($form_name, $form_value, $form_checked = 0, $form_tooltip = "", $form_js = "") {
function checkbox($name, $value, $checked = false, $options = array())

Select

just renaming method select_open option select_close
function form_option($form_option, $form_selected = "", $form_value = "", $form_js = "") {
...
return "\n";
}
function option($option_title, $value, $selected = false, $options = '')
return "";