| [ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 /** 3 * TTextBox class file. 4 * 5 * @author Qiang Xue <qiang.xue@gmail.com> 6 * @link http://www.pradosoft.com/ 7 * @copyright Copyright © 2005 PradoSoft 8 * @license http://www.pradosoft.com/license/ 9 * @version $Id: TTextBox.php 1397 2006-09-07 07:55:53Z wei $ 10 * @package System.Web.UI.WebControls 11 */ 12 13 /** 14 * TTextBox class 15 * 16 * TTextBox displays a text box on the Web page for user input. 17 * The text displayed in the TTextBox control is determined by the 18 * {@link setText Text} property. You can create a <b>SingleLine</b>, 19 * a <b>MultiLine</b>, or a <b>Password</b> text box by setting 20 * the {@link setTextMode TextMode} property. If the TTextBox control 21 * is a multiline text box, the number of rows it displays is determined 22 * by the {@link setRows Rows} property, and the {@link setWrap Wrap} property 23 * can be used to determine whether to wrap the text in the component. 24 * 25 * To specify the display width of the text box, in characters, set 26 * the {@link setColumns Columns} property. To prevent the text displayed 27 * in the component from being modified, set the {@link setReadOnly ReadOnly} 28 * property to true. If you want to limit the user input to a specified number 29 * of characters, set the {@link setMaxLength MaxLength} property. 30 * To use AutoComplete feature, set the {@link setAutoCompleteType AutoCompleteType} property. 31 * 32 * If {@link setAutoPostBack AutoPostBack} is set true, updating the text box 33 * and then changing the focus out of it will cause postback action. 34 * And if {@link setCausesValidation CausesValidation} is true, validation will 35 * also be processed, which can be further restricted within 36 * a {@link setValidationGroup ValidationGroup}. 37 * 38 * WARNING: Be careful if you want to display the text collected via TTextBox. 39 * Malicious cross-site script may be injected in. You may use {@link getSafeText SafeText} 40 * to prevent this problem. 41 * 42 * NOTE: If you set {@link setWrap Wrap} to false or use {@link setAutoCompleteType AutoCompleteType}, 43 * the generated HTML output for the textbox will not be XHTML-compatible. 44 * Currently, no alternatives are available. 45 * 46 * @author Qiang Xue <qiang.xue@gmail.com> 47 * @version $Id: TTextBox.php 1397 2006-09-07 07:55:53Z wei $ 48 * @package System.Web.UI.WebControls 49 * @since 3.0 50 */ 51 class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable 52 { 53 /** 54 * Default number of rows (for MultiLine text box) 55 */ 56 const DEFAULT_ROWS=4; 57 /** 58 * Default number of columns (for MultiLine text box) 59 */ 60 const DEFAULT_COLUMNS=20; 61 /** 62 * @var mixed safe text parser 63 */ 64 private static $_safeTextParser=null; 65 /** 66 * @var string safe textbox content with javascript stripped off 67 */ 68 private $_safeText; 69 70 /** 71 * @return string tag name of the textbox 72 */ 73 protected function getTagName() 74 { 75 return ($this->getTextMode()==='MultiLine')?'textarea':'input'; 76 } 77 78 /** 79 * Adds attribute name-value pairs to renderer. 80 * This method overrides the parent implementation with additional textbox specific attributes. 81 * @param THtmlWriter the writer used for the rendering purpose 82 */ 83 protected function addAttributesToRender($writer) 84 { 85 $page=$this->getPage(); 86 $page->ensureRenderInForm($this); 87 if(($uid=$this->getUniqueID())!=='') 88 $writer->addAttribute('name',$uid); 89 if(($textMode=$this->getTextMode())===TTextBoxMode::MultiLine) 90 { 91 if(($rows=$this->getRows())<=0) 92 $rows=self::DEFAULT_ROWS; 93 if(($cols=$this->getColumns())<=0) 94 $cols=self::DEFAULT_COLUMNS; 95 $writer->addAttribute('rows',"$rows"); 96 $writer->addAttribute('cols',"$cols"); 97 if(!$this->getWrap()) 98 $writer->addAttribute('wrap','off'); 99 } 100 else 101 { 102 if($textMode===TTextBoxMode::SingleLine) 103 { 104 $writer->addAttribute('type','text'); 105 if(($text=$this->getText())!=='') 106 $writer->addAttribute('value',$text); 107 if(($act=$this->getAutoCompleteType())!=='None') 108 { 109 if($act==='Disabled') 110 $writer->addAttribute('autocomplete','off'); 111 else if($act==='Search') 112 $writer->addAttribute('vcard_name','search'); 113 else if($act==='HomeCountryRegion') 114 $writer->addAttribute('vcard_name','HomeCountry'); 115 else if($act==='BusinessCountryRegion') 116 $writer->addAttribute('vcard_name','BusinessCountry'); 117 else 118 { 119 if(strpos($act,'Business')===0) 120 $act='Business'.'.'.substr($act,8); 121 else if(strpos($act,'Home')===0) 122 $act='Home'.'.'.substr($act,4); 123 $writer->addAttribute('vcard_name','vCard.'.$act); 124 } 125 } 126 } 127 else 128 { 129 $writer->addAttribute('type','password'); 130 } 131 if(($cols=$this->getColumns())>0) 132 $writer->addAttribute('size',"$cols"); 133 if(($maxLength=$this->getMaxLength())>0) 134 $writer->addAttribute('maxlength',"$maxLength"); 135 } 136 if($this->getReadOnly()) 137 $writer->addAttribute('readonly','readonly'); 138 $isEnabled=$this->getEnabled(true); 139 if(!$isEnabled && $this->getEnabled()) // in this case parent will not render 'disabled' 140 $writer->addAttribute('disabled','disabled'); 141 if($isEnabled && $this->getAutoPostBack() && $page->getClientSupportsJavaScript()) 142 { 143 $writer->addAttribute('id',$this->getClientID()); 144 $this->getPage()->getClientScript()->registerPostBackControl('Prado.WebUI.TTextBox',$this->getPostBackOptions()); 145 } 146 parent::addAttributesToRender($writer); 147 } 148 149 /** 150 * Gets the post back options for this textbox. 151 * @return array 152 */ 153 protected function getPostBackOptions() 154 { 155 $options['ID'] = $this->getClientID(); 156 $options['EventTarget'] = $this->getUniqueID(); 157 $options['CausesValidation'] = $this->getCausesValidation(); 158 $options['ValidationGroup'] = $this->getValidationGroup(); 159 $options['TextMode'] = $this->getTextMode(); 160 return $options; 161 } 162 163 /** 164 * Loads user input data. 165 * This method is primarly used by framework developers. 166 * @param string the key that can be used to retrieve data from the input data collection 167 * @param array the input data collection 168 * @return boolean whether the data of the component has been changed 169 */ 170 public function loadPostData($key,$values) 171 { 172 $value=$values[$key]; 173 if($this->getAutoTrim()) 174 $value=trim($value); 175 if(!$this->getReadOnly() && $this->getText()!==$value) 176 { 177 $this->setText($value); 178 return true; 179 } 180 else 181 return false; 182 } 183 184 /** 185 * Returns the value to be validated. 186 * This methid is required by IValidatable interface. 187 * @return mixed the value of the property to be validated. 188 */ 189 public function getValidationPropertyValue() 190 { 191 return $this->getText(); 192 } 193 194 /** 195 * Raises <b>OnTextChanged</b> event. 196 * This method is invoked when the value of the {@link getText Text} 197 * property changes on postback. 198 * If you override this method, be sure to call the parent implementation to ensure 199 * the invocation of the attached event handlers. 200 * @param TEventParameter event parameter to be passed to the event handlers 201 */ 202 public function onTextChanged($param) 203 { 204 $this->raiseEvent('OnTextChanged',$this,$param); 205 } 206 207 /** 208 * Raises postdata changed event. 209 * This method is required by {@link IPostBackDataHandler} interface. 210 * It is invoked by the framework when {@link getText Text} property 211 * is changed on postback. 212 * This method is primarly used by framework developers. 213 */ 214 public function raisePostDataChangedEvent() 215 { 216 if($this->getAutoPostBack() && $this->getCausesValidation()) 217 $this->getPage()->validate($this->getValidationGroup()); 218 $this->onTextChanged(null); 219 } 220 221 /** 222 * Renders the body content of the textbox when it is in MultiLine text mode. 223 * @param THtmlWriter the writer for rendering 224 */ 225 public function renderContents($writer) 226 { 227 if($this->getTextMode()==='MultiLine') 228 $writer->write(THttpUtility::htmlEncode($this->getText())); 229 } 230 231 /** 232 * @return TTextBoxAutoCompleteType the AutoComplete type of the textbox 233 */ 234 public function getAutoCompleteType() 235 { 236 return $this->getViewState('AutoCompleteType',TTextBoxAutoCompleteType::None); 237 } 238 239 /** 240 * @param TTextBoxAutoCompleteType the AutoComplete type of the textbox, default value is TTextBoxAutoCompleteType::None. 241 * @throws TInvalidDataValueException if the input parameter is not a valid AutoComplete type 242 */ 243 public function setAutoCompleteType($value) 244 { 245 $this->setViewState('AutoCompleteType',TPropertyValue::ensureEnum($value,'TTextBoxAutoCompleteType'),TTextBoxAutoCompleteType::None); 246 } 247 248 /** 249 * @return boolean a value indicating whether an automatic postback to the server 250 * will occur whenever the user modifies the text in the TTextBox control and 251 * then tabs out of the component. Defaults to false. 252 */ 253 public function getAutoPostBack() 254 { 255 return $this->getViewState('AutoPostBack',false); 256 } 257 258 /** 259 * Sets the value indicating if postback automatically. 260 * An automatic postback to the server will occur whenever the user 261 * modifies the text in the TTextBox control and then tabs out of the component. 262 * @param boolean the value indicating if postback automatically 263 */ 264 public function setAutoPostBack($value) 265 { 266 $this->setViewState('AutoPostBack',TPropertyValue::ensureBoolean($value),false); 267 } 268 269 /** 270 * @return boolean a value indicating whether the input text should be trimmed spaces. Defaults to false. 271 */ 272 public function getAutoTrim() 273 { 274 return $this->getViewState('AutoTrim',false); 275 } 276 277 /** 278 * Sets the value indicating if the input text should be trimmed spaces 279 * @param boolean the value indicating if the input text should be trimmed spaces 280 */ 281 public function setAutoTrim($value) 282 { 283 $this->setViewState('AutoTrim',TPropertyValue::ensureBoolean($value),false); 284 } 285 286 /** 287 * @return boolean whether postback event trigger by this text box will cause input validation, default is true. 288 */ 289 public function getCausesValidation() 290 { 291 return $this->getViewState('CausesValidation',true); 292 } 293 294 /** 295 * @param boolean whether postback event trigger by this text box will cause input validation. 296 */ 297 public function setCausesValidation($value) 298 { 299 $this->setViewState('CausesValidation',TPropertyValue::ensureBoolean($value),true); 300 } 301 302 /** 303 * @return integer the display width of the text box in characters, default is 0 meaning not set. 304 */ 305 public function getColumns() 306 { 307 return $this->getViewState('Columns',0); 308 } 309 310 /** 311 * Sets the display width of the text box in characters. 312 * @param integer the display width, set it 0 to clear the setting 313 */ 314 public function setColumns($value) 315 { 316 $this->setViewState('Columns',TPropertyValue::ensureInteger($value),0); 317 } 318 319 /** 320 * @return integer the maximum number of characters allowed in the text box, default is 0 meaning not set. 321 */ 322 public function getMaxLength() 323 { 324 return $this->getViewState('MaxLength',0); 325 } 326 327 /** 328 * Sets the maximum number of characters allowed in the text box. 329 * @param integer the maximum length, set it 0 to clear the setting 330 */ 331 public function setMaxLength($value) 332 { 333 $this->setViewState('MaxLength',TPropertyValue::ensureInteger($value),0); 334 } 335 336 /** 337 * @return boolean whether the textbox is read only, default is false. 338 */ 339 public function getReadOnly() 340 { 341 return $this->getViewState('ReadOnly',false); 342 } 343 344 /** 345 * @param boolean whether the textbox is read only 346 */ 347 public function setReadOnly($value) 348 { 349 $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false); 350 } 351 352 /** 353 * @return integer the number of rows displayed in a multiline text box, default is 4 354 */ 355 public function getRows() 356 { 357 return $this->getViewState('Rows',self::DEFAULT_ROWS); 358 } 359 360 /** 361 * Sets the number of rows displayed in a multiline text box. 362 * @param integer the number of rows 363 */ 364 public function setRows($value) 365 { 366 $this->setViewState('Rows',TPropertyValue::ensureInteger($value),self::DEFAULT_ROWS); 367 } 368 369 /** 370 * @return string the text content of the TTextBox control. 371 */ 372 public function getText() 373 { 374 return $this->getViewState('Text',''); 375 } 376 377 /** 378 * Sets the text content of the TTextBox control. 379 * @param string the text content 380 */ 381 public function setText($value) 382 { 383 $this->setViewState('Text',$value,''); 384 $this->_safeText = null; 385 } 386 387 /** 388 * @return string safe text content with javascript stripped off 389 */ 390 public function getSafeText() 391 { 392 if($this->_safeText===null) 393 $this->_safeText=$this->getSafeTextParser()->parse($this->getText()); 394 return $this->_safeText; 395 } 396 397 /** 398 * @return mixed safe text parser 399 */ 400 protected function getSafeTextParser() 401 { 402 if(!self::$_safeTextParser) 403 self::$_safeTextParser=Prado::createComponent('System.3rdParty.SafeHtml.TSafeHtmlParser'); 404 return self::$_safeTextParser; 405 } 406 407 /** 408 * @return TTextBoxMode the behavior mode of the TTextBox component. Defaults to TTextBoxMode::SingleLine. 409 */ 410 public function getTextMode() 411 { 412 return $this->getViewState('TextMode',TTextBoxMode::SingleLine); 413 } 414 415 /** 416 * Sets the behavior mode of the TTextBox component. 417 * @param TTextBoxMode the text mode 418 * @throws TInvalidDataValueException if the input value is not a valid text mode. 419 */ 420 public function setTextMode($value) 421 { 422 $this->setViewState('TextMode',TPropertyValue::ensureEnum($value,'TTextBoxMode'),TTextBoxMode::SingleLine); 423 } 424 425 /** 426 * @return string the group of validators which the text box causes validation upon postback 427 */ 428 public function getValidationGroup() 429 { 430 return $this->getViewState('ValidationGroup',''); 431 } 432 433 /** 434 * @param string the group of validators which the text box causes validation upon postback 435 */ 436 public function setValidationGroup($value) 437 { 438 $this->setViewState('ValidationGroup',$value,''); 439 } 440 441 /** 442 * @return boolean whether the text content wraps within a multiline text box. Defaults to true. 443 */ 444 public function getWrap() 445 { 446 return $this->getViewState('Wrap',true); 447 } 448 449 /** 450 * Sets the value indicating whether the text content wraps within a multiline text box. 451 * @param boolean whether the text content wraps within a multiline text box. 452 */ 453 public function setWrap($value) 454 { 455 $this->setViewState('Wrap',TPropertyValue::ensureBoolean($value),true); 456 } 457 } 458 459 /** 460 * TTextBoxMode class. 461 * TTextBoxMode defines the enumerable type for the possible mode 462 * that a {@link TTextBox} control could be at. 463 * 464 * The following enumerable values are defined: 465 * - SingleLine: the textbox will be a regular single line input 466 * - MultiLine: the textbox will be a textarea allowing multiple line input 467 * - Password: the textbox will hide user input like a password input box 468 * 469 * @author Qiang Xue <qiang.xue@gmail.com> 470 * @version $Id: TTextBox.php 1397 2006-09-07 07:55:53Z wei $ 471 * @package System.Web.UI.WebControls 472 * @since 3.0.4 473 */ 474 class TTextBoxMode extends TEnumerable 475 { 476 const SingleLine='SingleLine'; 477 const MultiLine='MultiLine'; 478 const Password='Password'; 479 } 480 481 /** 482 * TTextBoxAutoCompleteType class. 483 * TTextBoxAutoCompleteType defines the possible AutoComplete type that is supported 484 * by a {@link TTextBox} control. 485 * 486 * @author Qiang Xue <qiang.xue@gmail.com> 487 * @version $Id: TTextBox.php 1397 2006-09-07 07:55:53Z wei $ 488 * @package System.Web.UI.WebControls 489 * @since 3.0.4 490 */ 491 class TTextBoxAutoCompleteType extends TEnumerable 492 { 493 const BusinessCity='BusinessCity'; 494 const BusinessCountryRegion='BusinessCountryRegion'; 495 const BusinessFax='BusinessFax'; 496 const BusinessPhone='BusinessPhone'; 497 const BusinessState='BusinessState'; 498 const BusinessStreetAddress='BusinessStreetAddress'; 499 const BusinessUrl='BusinessUrl'; 500 const BusinessZipCode='BusinessZipCode'; 501 const Cellular='Cellular'; 502 const Company='Company'; 503 const Department='Department'; 504 const Disabled='Disabled'; 505 const DisplayName='DisplayName'; 506 const Email='Email'; 507 const FirstName='FirstName'; 508 const Gender='Gender'; 509 const HomeCity='HomeCity'; 510 const HomeCountryRegion='HomeCountryRegion'; 511 const HomeFax='HomeFax'; 512 const Homepage='Homepage'; 513 const HomePhone='HomePhone'; 514 const HomeState='HomeState'; 515 const HomeStreetAddress='HomeStreetAddress'; 516 const HomeZipCode='HomeZipCode'; 517 const JobTitle='JobTitle'; 518 const LastName='LastName'; 519 const MiddleName='MiddleName'; 520 const None='None'; 521 const Notes='Notes'; 522 const Office='Office'; 523 const Pager='Pager'; 524 const Search='Search'; 525 } 526 527 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |