Dotclear

Changeset 2208


Ignore:
Timestamp:
04/28/10 02:32:19 (13 years ago)
Author:
Oaz
Message:

Unstable commit. Completed refactoring and added tests for checkboxes and radio buttons.

Location:
plugins/myForms/trunk
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • plugins/myForms/trunk/Field.php

    r2207 r2208  
    3939  } 
    4040   
    41   abstract public function Display(); 
    42    
    4341  public function Input($defaultValue=false) { 
    4442    global $_REQUEST; 
     
    5351    return $this->Input($defaultValue); 
    5452  } 
     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 
    5595   
    5696  public static function BuildDeclaration($class,$attr,$content) { 
     
    80120  } 
    81121   
    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.")"; 
    88125  } 
    89126   
    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 Value 
    103127  protected static function BuildValueDisplay($attr,$content,$asHtml=false) 
    104128  { 
     129    $valueCode = self::BuildValueCode($attr,"ob_get_clean()"); 
    105130    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')); ?>"; 
    107132    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."; ?>"; 
    109134  } 
     135 
     136   
     137  //========================== 
     138  // template tags definitions 
    110139   
    111140  public static function Register() { 
     
    114143    $core->tpl->addBlock('myformsFieldMatches',array('MyFormsField','FieldMatches')); 
    115144    $core->tpl->addBlock('myformsFieldInputMatches',array('MyFormsField','FieldInputMatches')); 
     145    $core->tpl->addBlock('myformsFieldWarning',array('MyFormsField','FieldWarning')); 
    116146  } 
    117147   
     
    133163    return '<?php if( MyForms::getField("'.$attr['name'].'")->InputMatches("'.$attr['pattern'].'") ) { ?>'.$content.'<?php } ?>'; 
    134164  } 
     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  } 
    135171} 
     172 
     173MyFormsField::Register(); 
     174 
    136175?> 
  • plugins/myForms/trunk/TplCore.php

    r2207 r2208  
    9393      ."?>\n" 
    9494      .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}}'), 
    9797        $content 
    9898      )."\n" 
  • plugins/myForms/trunk/TplFields.php

    r2207 r2208  
    2020 
    2121$core->tpl->addValue('myformsFileFieldValue',array('MyFormsTplFields','FileFieldValue')); 
    22 $core->tpl->addBlock('myformsFieldWarning',array('MyFormsTplFields','FieldWarning')); 
    2322$core->tpl->addBlock('myformsTextArea',array('MyFormsTplFields','TextArea')); 
    24 $core->tpl->addValue('myformsCheckbox',array('MyFormsTplFields','Checkbox')); 
    25 $core->tpl->addValue('myformsRadioButton',array('MyFormsTplFields','RadioButton')); 
    2623$core->tpl->addValue('myformsFileField',array('MyFormsTplFields','FileField')); 
    2724$core->tpl->addValue('myformsHiddenField',array('MyFormsTplFields','HiddenField')); 
     
    6259  } 
    6360   
     61  /* 
    6462  // Validate Field 
    6563  public static function FieldWarning($attr,$content) 
     
    6765    return '<?php if( !MyForms::validateField("'.$attr['name'].'","'.$attr['validate'].'") ) { ?>'.$content.'<?php } ?>'; 
    6866  } 
     67  */ 
    6968   
    7069  // Display TextArea Field 
     
    7473  } 
    7574 
     75/* 
    7676  // Display Checkbox Field 
    7777  public static function Checkbox($attr) 
     
    8080    return "<input type='checkbox' ".self::GetAttributes($attr)." value='checked'".$checked." />"; 
    8181  } 
     82*/ 
    8283 
     84/* 
    8385  // Display Radio Button Field 
    8486  public static function RadioButton($attr) 
     
    8789    return "<input type='radio' ".self::GetAttributes($attr,$attr['name'],$attr['value']).$checked." />"; 
    8890  } 
     91*/ 
    8992 
    9093  // Display File Upload Field 
     
    112115  } 
    113116 
     117/* 
    114118  // Display Submit Field 
    115119  public static function Submit($attr,$content) 
     
    117121    return "<input type='submit' ".self::GetAttributes($attr)." value='".self::getFieldValue($attr,$content)."' />"; 
    118122  } 
    119  
     123*/ 
    120124} 
    121125?> 
  • plugins/myForms/trunk/_public.php

    r2207 r2208  
    2020 
    2121require_once("Field.php"); 
    22 MyFormsField::Register(); 
    2322require_once("FieldSet.php"); 
    2423require_once("fields/TextField.php"); 
    25 MyFormsTextField::Register(); 
    2624require_once("fields/SubmitField.php"); 
    27 MyFormsSubmitField::Register(); 
    2825require_once("fields/ComboField.php"); 
    29 MyFormsComboField::Register(); 
     26require_once("fields/CheckBoxField.php"); 
     27require_once("fields/RadioButtonField.php"); 
    3028 
    3129require_once("TplCore.php"); 
     
    5654  private static $htmlOut; 
    5755  private static $formHTML; 
    58   private static $allFieldsAreValidated; 
     56  private static $formIsValid; 
    5957  private static $captchaIsValidated; 
    6058  private static $passwordProtected; 
     
    9593     
    9694    // process  form post 
    97     if( isset($_REQUEST["myforms"]) && self::$captchaIsValidated && self::$allFieldsAreValidated ) { 
     95    if( isset($_REQUEST["myforms"]) && self::$captchaIsValidated && self::$formIsValid ) { 
    9896      self::$nextFormID = false; 
    9997      self::$errors = array(); 
     
    159157     
    160158    // field display and validation 
    161     self::$allFieldsAreValidated = true; 
     159    self::$formIsValid = true; 
    162160    self::$captchaIsValidated = true; 
    163161    ob_start(); 
     
    166164    self::$htmlOut = ob_get_clean(); 
    167165  } 
    168    
     166    
     167  public static function InvalidateForm() { 
     168    self::$formIsValid = false; 
     169  } 
     170  
    169171  public static function validateCaptcha() { 
    170172    global $_REQUEST; 
  • plugins/myForms/trunk/demo/checkboxes.myforms.html

    r1048 r2208  
    2222  <tpl:myformsFieldMatches name="blue" pattern="^$">You do not like blue.</tpl:myformsFieldMatches> 
    2323  </p> 
     24  <p><strong>Try again !</strong></p> 
     25  {{tpl:myformsDisplay}} 
    2426</tpl:myformsOnSubmit> 
  • plugins/myForms/trunk/fields/ComboField.php

    r2207 r2208  
    8383 } 
    8484} 
     85 
     86MyFormsComboField::Register(); 
     87 
    8588?> 
  • plugins/myForms/trunk/fields/SubmitField.php

    r2207 r2208  
    4747  } 
    4848} 
     49 
     50MyFormsSubmitField::Register(); 
     51 
    4952?> 
  • plugins/myForms/trunk/fields/TextField.php

    r2207 r2208  
    2121class MyFormsTextField extends MyFormsField 
    2222{ 
    23   private $choices; 
    24    
    2523  public function __construct() { 
    2624    parent::__construct(func_get_args()); 
     
    4947  } 
    5048} 
     49 
     50MyFormsTextField::Register(); 
     51 
    5152?> 
  • plugins/myForms/trunk/tests/_All

    r2207 r2208  
    1212<tr><td><a href="Combo">Combo</a></td></tr> 
    1313<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> 
    1417</tbody></table> 
    1518</body> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map