Well, I am not good at scripting, and I am kinda Photoshop guy. I am also new at PHP, so please bear with me. I am currently creating web form generation class which needs to be reusable and flexible for localization.
What I hope to ask at here is:
How I can pass var from one function($avInq->textFeild) to the other function($avInq->JStextField).
What I need to let the functions share are:
$field_name ('form_note'),
$max_length ('250'),
$cols ('2'),
$rows ('30'),
$value
I could not pass those vars to $avInq->JStextField, so I used strtr() like:
$trans = array('%field_name%'=>$field_name,'%max_length%'=>$max_length,'%cols%'=>$cols,'%rows%'=>$rows, '%value%'=>$value);
$field = strtr($js,$trans);
And I feel there must be better way.
Here is my entire code and you will be get what I am talking:
class formGenerator {
public function textFeild ($field_label=true, $field_name, $cols, $rows, $max_length, $js=true){
$escName = htmlentities($field_name);
$value = $this-> getValue($field_name);
$non_req = $this->getNotRequiredData($locale);//Get what non-reuired form is from languages
$req = (in_array($field_name,$non_req)) ? '' : '*' ; //If non-req is in the field_name, then check it.
$label = $field_label ? "$req$field_label" : "";
if(isset($js)){
$trans = array('%field_name%'=>$field_name,'%max_length%'=>$max_length,'%cols%'=>$cols,'%rows%'=>$rows, '%value%'=>$value);
$field = strtr($js,$trans);
} else {
$field = "$value";
}
$output = $label.$field;
print "".$output."";
}
public function JStextField ($js_action,$js_func,$input_guid_txt){
if(isset($js_action)){
$js_call = $js_action.'="'.$js_func.'"';
$field = "%value%";
$html_guid = "$input_guid_txt
Max:%max_length%";
$field = $field.$html_guid;
return $field;
} else {
die('dont do anything');
}
}
};
// Call php class
$avInq = new formGenerator;
$varfooo = $avInq->JStextField ('onkeyup','return checklength(this,contact_max_warning)','Characters typed:');
$avInq->textFeild('Note','form_note','2','20','250',$varfooo);
Thanks.