1: | <?php
|
2: |
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: |
|
9: | namespace Sphp\comp\html{
|
10: |
|
11: | class HTMLForm extends \Sphp\tools\Control {
|
12: |
|
13: | public $recID = 'txtid';
|
14: | private $onvalidation = '';
|
15: | private $blnajax = false;
|
16: | private $ajax = null;
|
17: | private $target = "";
|
18: |
|
19: | protected function genhelpPropList() {
|
20: | parent::genhelpPropList();
|
21: | $this->addHelpPropFunList('setAjax','Set Form post as AJAX','','');
|
22: | $this->addHelpPropFunList('setOnValidation','JS Function call on form validation and return false stop form to submit','','$jscode');
|
23: | }
|
24: |
|
25: | public function setupJSLib() {
|
26: | addFileLink($this->myrespath . "/jslib/validation.js", true);
|
27: | addFileLink($this->myrespath . "/jslib/jquery.form.js", true);
|
28: | }
|
29: | public function oninit() {
|
30: | $this->tagName = "form";
|
31: | addFileLink($this->myrespath . "/jslib/validation.js", true);
|
32: | }
|
33: |
|
34: | public function setAjax() {
|
35: | $this->blnajax = true;
|
36: | addFileLink($this->myrespath . "/jslib/jquery.form.js", true);
|
37: | }
|
38: |
|
39: | public function setAjaxTarget($val) {
|
40: | $this->target = $val;
|
41: | }
|
42: |
|
43: | public function setRecID($val) {
|
44: | $this->recID = $val;
|
45: | }
|
46: |
|
47: | public function getRecID() {
|
48: | return $this->recID;
|
49: | }
|
50: |
|
51: | public function setOnValidation($val) {
|
52: | $this->onvalidation = $val;
|
53: | }
|
54: |
|
55: | public function onprejsrender() {
|
56: | $valdx = "";
|
57: | if ($this->blnajax) {
|
58: | \SphpBase::JSServer()->getAJAX();
|
59: | if ($this->target == '') {
|
60: | $divt = '<div style="visibility:hidden;"><img src="' . \SphpBase::sphp_settings()->res_path . '/'. \SphpBase::sphp_settings()->slib_version . '/comp/html/res/ajax-loader.gif" />' . "</div><div id=\"" . $this->name . "res\"></div>";
|
61: | $this->target = $this->name . "res";
|
62: | } else {
|
63: | $divt = "";
|
64: | }
|
65: |
|
66: | $this->setPreTag($divt);
|
67: | $subcode = "$('#{$this->name}').find(\"input[type='submit']\").attr('disabled',true);
|
68: | jql('#" . $this->name . "').ajaxSubmit({
|
69: | dataType: 'text',
|
70: | success: function(html) {
|
71: | if(document.getElementById('ajax_loader')!=null){
|
72: | document.getElementById('ajax_loader').style.visibility = 'hidden';
|
73: | }
|
74: | $('#{$this->name}').find(\"input[type='submit']\").attr('disabled',false);
|
75: |
|
76: | sartajpro(html,function(res){});
|
77: | }
|
78: | });
|
79: | ";
|
80: |
|
81: | |
82: | |
83: | |
84: | |
85: | |
86: | |
87: | |
88: | |
89: | |
90: | |
91: | |
92: |
|
93: |
|
94: |
|
95: | } else {
|
96: | $subcode = "
|
97: | if(val==''){
|
98: | objc1.submit();
|
99: | }else{
|
100: | objc1.action=val;
|
101: | objc1.submit();
|
102: | }
|
103: | ";
|
104: | }
|
105: | if ($this->onvalidation != '') {
|
106: | $valdx = "if(blnSubmit==true){
|
107: | blnSubmit = " . $this->onvalidation . ";
|
108: | }
|
109: | ";
|
110: | }
|
111: | addFooterJSFunction($this->name . "_submit", "function " . $this->name . "_submit(val){
|
112: | var blnSubmit = true ;
|
113: | var ctlReq = Array();
|
114: | var ctlEmail = Array();
|
115: | var ctlNums = Array();
|
116: | var ctlMins = Array();
|
117: | var ctlMax = Array();
|
118: | ", "
|
119: | if(blnSubmit==true && checkTextEmpty(ctlReq)==false){
|
120: | blnSubmit = false ;
|
121: | }
|
122: | if(blnSubmit==true && checkmax(ctlMax)==false){
|
123: | blnSubmit = false ;
|
124: | }
|
125: | if(blnSubmit==true && checkmin(ctlMins)==false){
|
126: | blnSubmit = false ;
|
127: | }
|
128: | if(blnSubmit==true && checkemails(ctlEmail)==false){
|
129: | blnSubmit = false ;
|
130: | }
|
131: | if(blnSubmit==true && checknums(ctlNums)==false){
|
132: | blnSubmit = false ;
|
133: | }
|
134: | $valdx
|
135: | if(blnSubmit==true ){
|
136: | var objc1 = document.getElementById('" . $this->name . "');
|
137: | $subcode
|
138: | }
|
139: | return false;
|
140: | }");
|
141: | }
|
142: |
|
143: | public function onrender() {
|
144: | $this->setAttributeDefault("role","form");
|
145: | $this->setAttributeDefault("method","post");
|
146: | $this->setAttributeDefault("enctype","multipart/form-data");
|
147: | $this->setAttributeDefault("action",getThisURL());
|
148: |
|
149: | if(!isset($this->onsubmit)){
|
150: | addHeaderJSFunctionCode("ready", $this->name .'rd1', "jql('#" . $this->name . "').on('submit',function(){var vt = " . $this->name . "_submit(''); event.preventDefault(); return false;}); ");
|
151: | }
|
152: | $hdn = "<input type=\"hidden\" name=\"" . $this->recID . "\" value=\"" . \SphpBase::sphp_request()->request($this->recID) . "\" />";
|
153: | if($this->blnajax) $hdn .= "<input type=\"hidden\" name=\"sphpajax\" value=\"1\" />";
|
154: | $this->appendHTML($hdn);
|
155: | $parenttag = $this->wrapTag("div");
|
156: | $parenttag->setAttribute("id","wrp" . $this->name);
|
157: | }
|
158: |
|
159: | }
|
160: |
|
161: | }
|
162: | |