好吧,我不擅长脚本,我是一个photoshop的家伙。我也是新来的,所以请容忍我。
我目前正在创建web表单生成类,它需要可重用和灵活的本地化。
我想问的是:
如何将变量从一个函数($avinq->textfield)传递到另一个函数($avinq->jstextfield)。
我需要让函数共享的是:
$field_name('form_note'),
$最大长度('250'),
$ Cals('2))
$rows('30'),
美元价值
我无法将这些变量传递给$avinq->jstextfield,因此我使用strtr()如下:
$trans = array('%field_name%'=>$field_name,'%max_length%'=>$max_length,'%cols%'=>$cols,'%rows%'=>$rows, '%value%'=>$value);
$field = strtr($js,$trans);
我觉得一定有更好的办法。
这是我的全部代码,你会明白我在说什么:
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);
谢谢。