Dotclear

source: plugins/myForms/trunk/TplFields.php @ 2208

Revision 2208, 4.2 KB checked in by Oaz, 14 years ago (diff)

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

Line 
1<?php
2# ***** BEGIN LICENSE BLOCK *****
3# Copyright (c) 2009 Olivier Azeau and contributors. All rights  reserved.
4#
5# This is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with DotClear; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18#
19# ***** END LICENSE BLOCK *****
20
21$core->tpl->addValue('myformsFileFieldValue',array('MyFormsTplFields','FileFieldValue'));
22$core->tpl->addBlock('myformsTextArea',array('MyFormsTplFields','TextArea'));
23$core->tpl->addValue('myformsFileField',array('MyFormsTplFields','FileField'));
24$core->tpl->addValue('myformsHiddenField',array('MyFormsTplFields','HiddenField'));
25$core->tpl->addValue('myformsCaptchaField',array('MyFormsTplFields','CaptchaField'));
26$core->tpl->addBlock('myformsCaptchaWarning',array('MyFormsTplFields','CaptchaWarning'));
27
28class MyFormsTplFields
29{
30  // Field Attributes
31  private static function GetAttributes($attr,$name=false,$id=false)
32  {
33    if( $name )
34      $attr['name'] = $name;
35    if( !$id )
36      $id = $attr['name'];
37    $attributes = "id='myforms_".$id."' name='myforms[".$attr['name']."]'";
38    foreach( $attr as $k => $v )
39      if( $k != 'name' )
40        $attributes .= " ".$k."='".$v."'";
41    return $attributes;
42  }
43 
44  /*
45  // Field Value
46  private static function getFieldValue($attr,$content,$asHtml)
47  {
48    if( $asHtml )
49      return '<?php ob_start(); ?>'.$content.'<?php echo nl2br(htmlentities(MyForms::getFieldValue("'.$attr['name'].'",ob_get_clean()),ENT_QUOTES,"UTF-8")); ?>';
50    else
51      return '<?php ob_start(); ?>'.$content.'<?php echo MyForms::getFieldValue("'.$attr['name'].'",ob_get_clean()); ?>';
52  }
53  */
54 
55  // File Field Value
56  public static function FileFieldValue($attr)
57  {
58    return '<?php echo MyForms::getFileFieldValue("'.$attr['name'].'","'.$attr['data'].'"); ?>';
59  }
60 
61  /*
62  // Validate Field
63  public static function FieldWarning($attr,$content)
64  {
65    return '<?php if( !MyForms::validateField("'.$attr['name'].'","'.$attr['validate'].'") ) { ?>'.$content.'<?php } ?>';
66  }
67  */
68 
69  // Display TextArea Field
70  public static function TextArea($attr,$content)
71  {
72    return "<textarea ".self::GetAttributes($attr).">".self::getFieldValue($attr,$content)."</textarea>";
73  }
74
75/*
76  // Display Checkbox Field
77  public static function Checkbox($attr)
78  {
79    $checked = '<?php echo MyForms::getFieldValue("'.$attr['name'].'","")?" checked=\'1\'":""; ?>';
80    return "<input type='checkbox' ".self::GetAttributes($attr)." value='checked'".$checked." />";
81  }
82*/
83
84/*
85  // Display Radio Button Field
86  public static function RadioButton($attr)
87  {
88    $checked = '<?php echo (MyForms::getFieldValue("'.$attr['name'].'","")=="'.$attr['value'].'")?" checked=\'1\'":""; ?>';
89    return "<input type='radio' ".self::GetAttributes($attr,$attr['name'],$attr['value']).$checked." />";
90  }
91*/
92
93  // Display File Upload Field
94  public static function FileField($attr)
95  {
96    return "<input type='file' ".self::GetAttributes($attr)." />";
97  }
98
99  // Display Hidden Field
100  public static function HiddenField($attr)
101  {
102    return "<input type='hidden' ".self::GetAttributes($attr)." value='".self::getFieldValue($attr,'')."' />";
103  }
104
105  // Display Captcha Field
106  public static function CaptchaField($attr,$content)
107  {
108    return '<?php MyFormsCaptcha::display("'.self::GetAttributes($attr,'captcharef').'","'.self::GetAttributes($attr,'captcha').'"); ?>';
109  }
110
111  // Display Warning when Captcha code do not match
112  public static function CaptchaWarning($attr,$content)
113  {
114    return '<?php if( !MyForms::validateCaptcha() ) { ?>'.$content.'<?php } ?>';
115  }
116
117/*
118  // Display Submit Field
119  public static function Submit($attr,$content)
120  {
121    return "<input type='submit' ".self::GetAttributes($attr)." value='".self::getFieldValue($attr,$content)."' />";
122  }
123*/
124}
125?>
Note: See TracBrowser for help on using the repository browser.

Sites map