Changeset 2208
- Timestamp:
- 04/28/10 02:32:19 (13 years ago)
- Location:
- plugins/myForms/trunk
- Files:
-
- 5 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/myForms/trunk/Field.php
r2207 r2208 39 39 } 40 40 41 abstract public function Display();42 43 41 public function Input($defaultValue=false) { 44 42 global $_REQUEST; … … 53 51 return $this->Input($defaultValue); 54 52 } 53 54 public function IsValid($condition) { 55 global $_REQUEST; 56 $fieldIsValid = !isset($_REQUEST["myforms"]) || preg_match('#'.$condition.'#', @$_REQUEST["myforms"][$this->Name()]); 57 if(!$fieldIsValid) 58 MyForms::InvalidateForm(); 59 return $fieldIsValid; 60 } 61 62 public function InputMatches($pattern) { 63 return preg_match('#'.$pattern.'#', $this->Input()); 64 } 65 66 public function Matches($pattern) { 67 return preg_match('#'.$pattern.'#', $this->Value()); 68 } 69 70 71 //========================= 72 // template code generation 73 74 abstract public function Display(); 75 76 public function AttributesAsString() { 77 $str = "id='myforms_".$this->attributes['id']."' name='myforms[".$this->attributes['name']."]'"; 78 foreach( $this->attributes as $k => $v ) 79 if( $k != 'name' && $k != 'id' ) 80 $str .= " ".$k."='".$v."'"; 81 return $str; 82 } 83 84 public function ValueCode($defaultValue='') { 85 return self::BuildValueCode($this->attributes,$defaultValue); 86 } 87 88 public function ValueDisplay() { 89 return self::BuildValueDisplay($this->attributes,$this->content,isset($this->attributes['html'])); 90 } 91 92 93 //========================= 94 // static utility functions 55 95 56 96 public static function BuildDeclaration($class,$attr,$content) { … … 80 120 } 81 121 82 public function AttributesAsString() { 83 $str = "id='myforms_".$this->attributes['id']."' name='myforms[".$this->attributes['name']."]'"; 84 foreach( $this->attributes as $k => $v ) 85 if( $k != 'name' && $k != 'id' ) 86 $str .= " ".$k."='".$v."'"; 87 return $str; 122 protected static function BuildValueCode($attr,$defaultValue) 123 { 124 return "MyForms::getField('".$attr['name']."')->Value(".$defaultValue.")"; 88 125 } 89 126 90 public function ValueDisplay() {91 return self::BuildValueDisplay($this->attributes,$this->content,isset($this->attributes['html']));92 }93 94 public function InputMatches($pattern) {95 return preg_match('#'.$pattern.'#', $this->Input());96 }97 98 public function Matches($pattern) {99 return preg_match('#'.$pattern.'#', $this->Value());100 }101 102 // Field Value103 127 protected static function BuildValueDisplay($attr,$content,$asHtml=false) 104 128 { 129 $valueCode = self::BuildValueCode($attr,"ob_get_clean()"); 105 130 if( $asHtml ) 106 return "<?php ob_start(); ?>".$content."<?php print nl2br(htmlentities( MyForms::getField('".$attr['name']."')->Value(ob_get_clean()),ENT_QUOTES,'UTF-8')); ?>";131 return "<?php ob_start(); ?>".$content."<?php print nl2br(htmlentities(".$valueCode.",ENT_QUOTES,'UTF-8')); ?>"; 107 132 else 108 return "<?php ob_start(); ?>".$content."<?php print MyForms::getField('".$attr['name']."')->Value(ob_get_clean()); ?>";133 return "<?php ob_start(); ?>".$content."<?php print ".$valueCode."; ?>"; 109 134 } 135 136 137 //========================== 138 // template tags definitions 110 139 111 140 public static function Register() { … … 114 143 $core->tpl->addBlock('myformsFieldMatches',array('MyFormsField','FieldMatches')); 115 144 $core->tpl->addBlock('myformsFieldInputMatches',array('MyFormsField','FieldInputMatches')); 145 $core->tpl->addBlock('myformsFieldWarning',array('MyFormsField','FieldWarning')); 116 146 } 117 147 … … 133 163 return '<?php if( MyForms::getField("'.$attr['name'].'")->InputMatches("'.$attr['pattern'].'") ) { ?>'.$content.'<?php } ?>'; 134 164 } 165 166 // Field Matching 167 public static function FieldWarning($attr,$content) 168 { 169 return '<?php if( MyForms::getField("'.$attr['name'].'")->IsValid("'.$attr['validate'].'") ) { ?>'.$content.'<?php } ?>'; 170 } 135 171 } 172 173 MyFormsField::Register(); 174 136 175 ?> -
plugins/myForms/trunk/TplCore.php
r2207 r2208 93 93 ."?>\n" 94 94 .preg_replace( 95 array('#<tpl:(.*?)( .*?)?>#','#</tpl:(.*?)>#' ),96 array('<tpl:$1_Declare$2>','</tpl:$1_Declare>' ),95 array('#<tpl:(.*?)( .*?)?>#','#</tpl:(.*?)>#','#{{tpl:(.*?)( .*?)?}}#'), 96 array('<tpl:$1_Declare$2>','</tpl:$1_Declare>','{{tpl:$1_Declare$2}}'), 97 97 $content 98 98 )."\n" -
plugins/myForms/trunk/TplFields.php
r2207 r2208 20 20 21 21 $core->tpl->addValue('myformsFileFieldValue',array('MyFormsTplFields','FileFieldValue')); 22 $core->tpl->addBlock('myformsFieldWarning',array('MyFormsTplFields','FieldWarning'));23 22 $core->tpl->addBlock('myformsTextArea',array('MyFormsTplFields','TextArea')); 24 $core->tpl->addValue('myformsCheckbox',array('MyFormsTplFields','Checkbox'));25 $core->tpl->addValue('myformsRadioButton',array('MyFormsTplFields','RadioButton'));26 23 $core->tpl->addValue('myformsFileField',array('MyFormsTplFields','FileField')); 27 24 $core->tpl->addValue('myformsHiddenField',array('MyFormsTplFields','HiddenField')); … … 62 59 } 63 60 61 /* 64 62 // Validate Field 65 63 public static function FieldWarning($attr,$content) … … 67 65 return '<?php if( !MyForms::validateField("'.$attr['name'].'","'.$attr['validate'].'") ) { ?>'.$content.'<?php } ?>'; 68 66 } 67 */ 69 68 70 69 // Display TextArea Field … … 74 73 } 75 74 75 /* 76 76 // Display Checkbox Field 77 77 public static function Checkbox($attr) … … 80 80 return "<input type='checkbox' ".self::GetAttributes($attr)." value='checked'".$checked." />"; 81 81 } 82 */ 82 83 84 /* 83 85 // Display Radio Button Field 84 86 public static function RadioButton($attr) … … 87 89 return "<input type='radio' ".self::GetAttributes($attr,$attr['name'],$attr['value']).$checked." />"; 88 90 } 91 */ 89 92 90 93 // Display File Upload Field … … 112 115 } 113 116 117 /* 114 118 // Display Submit Field 115 119 public static function Submit($attr,$content) … … 117 121 return "<input type='submit' ".self::GetAttributes($attr)." value='".self::getFieldValue($attr,$content)."' />"; 118 122 } 119 123 */ 120 124 } 121 125 ?> -
plugins/myForms/trunk/_public.php
r2207 r2208 20 20 21 21 require_once("Field.php"); 22 MyFormsField::Register();23 22 require_once("FieldSet.php"); 24 23 require_once("fields/TextField.php"); 25 MyFormsTextField::Register();26 24 require_once("fields/SubmitField.php"); 27 MyFormsSubmitField::Register();28 25 require_once("fields/ComboField.php"); 29 MyFormsComboField::Register(); 26 require_once("fields/CheckBoxField.php"); 27 require_once("fields/RadioButtonField.php"); 30 28 31 29 require_once("TplCore.php"); … … 56 54 private static $htmlOut; 57 55 private static $formHTML; 58 private static $ allFieldsAreValidated;56 private static $formIsValid; 59 57 private static $captchaIsValidated; 60 58 private static $passwordProtected; … … 95 93 96 94 // process form post 97 if( isset($_REQUEST["myforms"]) && self::$captchaIsValidated && self::$ allFieldsAreValidated ) {95 if( isset($_REQUEST["myforms"]) && self::$captchaIsValidated && self::$formIsValid ) { 98 96 self::$nextFormID = false; 99 97 self::$errors = array(); … … 159 157 160 158 // field display and validation 161 self::$ allFieldsAreValidated = true;159 self::$formIsValid = true; 162 160 self::$captchaIsValidated = true; 163 161 ob_start(); … … 166 164 self::$htmlOut = ob_get_clean(); 167 165 } 168 166 167 public static function InvalidateForm() { 168 self::$formIsValid = false; 169 } 170 169 171 public static function validateCaptcha() { 170 172 global $_REQUEST; -
plugins/myForms/trunk/demo/checkboxes.myforms.html
r1048 r2208 22 22 <tpl:myformsFieldMatches name="blue" pattern="^$">You do not like blue.</tpl:myformsFieldMatches> 23 23 </p> 24 <p><strong>Try again !</strong></p> 25 {{tpl:myformsDisplay}} 24 26 </tpl:myformsOnSubmit> -
plugins/myForms/trunk/fields/ComboField.php
r2207 r2208 83 83 } 84 84 } 85 86 MyFormsComboField::Register(); 87 85 88 ?> -
plugins/myForms/trunk/fields/SubmitField.php
r2207 r2208 47 47 } 48 48 } 49 50 MyFormsSubmitField::Register(); 51 49 52 ?> -
plugins/myForms/trunk/fields/TextField.php
r2207 r2208 21 21 class MyFormsTextField extends MyFormsField 22 22 { 23 private $choices;24 25 23 public function __construct() { 26 24 parent::__construct(func_get_args()); … … 49 47 } 50 48 } 49 50 MyFormsTextField::Register(); 51 51 52 ?> -
plugins/myForms/trunk/tests/_All
r2207 r2208 12 12 <tr><td><a href="Combo">Combo</a></td></tr> 13 13 <tr><td><a href="ComboMatchValue">ComboMatchValue</a></td></tr> 14 <tr><td><a href="ComboMatchOtherValue">ComboMatchOtherValue</a></td></tr> 15 <tr><td><a href="CheckBoxes">CheckBoxes</a></td></tr> 16 <tr><td><a href="RadioButtons">RadioButtons</a></td></tr> 14 17 </tbody></table> 15 18 </body>
Note: See TracChangeset
for help on using the changeset viewer.