1: <?php
2:
3: /**
4: * Description of textfield
5: *
6: * @author SARTAJ
7: */
8:
9: namespace Sphp\Comp\Form{
10:
11: class TextArea extends \Sphp\tools\Component {
12:
13: public $maxLen = '';
14: public $minLen = '';
15: public $formName = '';
16: private $errmsg = '';
17: private $msgName = '';
18: private $req = false;
19:
20: protected function genhelpPropList() {
21: parent::genhelpPropList();
22: $this->addHelpPropFunList('setForm','Bind with Form JS Event','','$val');
23: $this->addHelpPropFunList('setMsgName','Name Display in placeholder and Error','','$val');
24: $this->addHelpPropFunList('setRequired','Can not submit Empty','','');
25: $this->addHelpPropFunList('setMaxLen','Maximum Accept Length','','$val');
26: $this->addHelpPropFunList('setMinLen','Minimum Accept Length','','$val');
27: }
28:
29: protected function oninit() {
30: $this->tagName = "textarea";
31: if ($this->issubmit) {
32: $this->value = htmlentities($this->value, ENT_COMPAT, "UTF-8");
33: }
34: if($this->getAttribute("msgname") != ""){
35: $this->msgName = $this->getAttribute("msgname");
36: }
37: if(!$this->element->hasAttribute("name")){
38: $this->HTMLName = $this->name;
39: }else{
40: $this->HTMLName = $this->getAttribute("name");
41: }
42:
43: }
44: public function setErrMsg($msg){
45: $this->errmsg .= '<strong class="alert-danger">' . $msg . '</strong>';
46: if(\SphpBase::sphp_request()->isAJAX()){
47: \SphpBase::JSServer()->addJSONJSBlock('$("#'. $this->name .'").after("<strong class=\"alert-danger\">' . $msg . '! </strong>");');
48: }
49: setErr($this->name, $msg);
50: }
51:
52: public function fi_setForm($val) {
53: $this->formName = $val;
54: }
55:
56: public function fu_setMsgName($val) {
57: $this->msgName = $val;
58: $this->setAttribute('placeholder', $val);
59: }
60:
61: public function fi_setRequired() {
62: if ($this->issubmit) {
63: if (strlen($this->value) < 1) {
64: $this->setErrMsg( $this->getAttribute("msgname") .' ' . "Can not submit Empty");
65: }
66: }
67: $this->req = true;
68: }
69:
70: public function fi_setMaxLen($val) {
71: $this->maxLen = $val;
72: if ($this->issubmit) {
73: if (strlen($this->value) > $val) {
74: $this->setErrMsg( $this->getAttribute("msgname") .' ' . "Maximum Characters should not be exceed then $val");
75: }
76: }
77: }
78:
79: public function getMaxLen() {
80: return $this->maxLen;
81: }
82:
83: public function fi_setMinLen($val) {
84: $this->minLen = $val;
85: if ($this->issubmit) {
86: if (strlen($this->getValue()) < $val) {
87: $this->setErrMsg( $this->getAttribute("msgname") .' ' . "Minimum Characters should be $val");
88: }
89: }
90: }
91:
92: public function getMinLen() {
93: return $this->minLen;
94: }
95:
96: protected function onjsrender() {
97: if ($this->formName != '') {
98: if ($this->minLen != '') {
99: addHeaderJSFunctionCode("{$this->formName}_submit", "{$this->name}min", "
100: ctlMins['$this->name']= Array('$this->msgName','TextArea','$this->minLen');");
101: }
102: if ($this->maxLen != '') {
103: addHeaderJSFunctionCode("{$this->formName}_submit", "{$this->name}max", "
104: ctlMax['$this->name']= Array('$this->msgName','TextArea','$this->maxLen');");
105: }
106: if ($this->req) {
107: addHeaderJSFunctionCode("{$this->formName}_submit", "{$this->name}req", "
108: ctlReq['$this->name']= Array('$this->msgName','TextArea');");
109: }
110: }
111: }
112:
113: protected function onrender() {
114: if($this->errmsg!=""){
115: $this->setPostTag($this->errmsg);
116: }
117: if ($this->getAttribute('class') == '') {
118: $this->class = "form-control";
119: }
120: if ($this->value != '') {
121: $this->setInnerHTML($this->value);
122: }
123: if($this->getVisible()){
124: $this->setAttributeDefault('rows', '10');
125: $this->setAttributeDefault('cols', '20');
126: switch($this->styler){
127: case 1:{
128: $this->setPreTag('<div class="form-floating mb-3">');
129: $this->setPostTag('<label for="'. $this->HTMLID .'" class="form-label">'. $this->msgName .'</label></div>');
130: break;
131: }case 2:{
132: $this->setPreTag('<div class="mb-3">
133: <label for="'. $this->HTMLID .'" class="form-label">'. $this->msgName .'</label>');
134: $this->setPostTag('<div id="'. $this->HTMLID .'Help" class="form-text">'. $this->helptext .'</div></div>');
135: break;
136: }
137: }
138: }else{
139: $this->element->setAttribute("value", $this->getInnerHTML());
140: $this->setInnerHTML('');
141: }
142: }
143:
144: // javascript functions used by ajax control and other control
145: public function getJSValue() {
146: return "document.getElementById('$this->name').value";
147: }
148:
149: public function setJSValue($exp) {
150: return "document.getElementById('$this->name').value = $exp;";
151: }
152:
153: }
154:
155: }
156: