| 1 |
jonen |
1.1 |
<?php |
| 2 |
|
|
/** |
| 3 |
|
|
* This file contains the FEText, FEName, FEEmail, |
| 4 |
|
|
* FEDomainName classes |
| 5 |
|
|
* |
| 6 |
jonen |
1.4 |
* $Id: FEText.inc,v 1.22.2.1 2005/05/12 01:24:03 hemna Exp $ |
| 7 |
jonen |
1.1 |
* |
| 8 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 9 |
jonen |
1.1 |
* @author Suren Markosyan <suren@bcsweb.com> |
| 10 |
|
|
* @package phpHtmlLib |
| 11 |
|
|
* @subpackage FormProcessing |
| 12 |
|
|
* |
| 13 |
|
|
* @copyright LGPL - See LICENCE |
| 14 |
|
|
* |
| 15 |
|
|
*/ |
| 16 |
|
|
|
| 17 |
|
|
/** |
| 18 |
|
|
* This is the Text FormElement which builds a |
| 19 |
|
|
* text input field. It has no validation method. |
| 20 |
|
|
* |
| 21 |
|
|
* |
| 22 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 23 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
| 24 |
|
|
* @package phpHtmlLib |
| 25 |
|
|
* @subpackage FormProcessing |
| 26 |
|
|
* |
| 27 |
|
|
* @copyright LGPL - See LICENCE |
| 28 |
|
|
*/ |
| 29 |
|
|
class FEText extends FormElement { |
| 30 |
|
|
|
| 31 |
|
|
/** |
| 32 |
|
|
* The constructor |
| 33 |
|
|
* |
| 34 |
|
|
* @param label string - text label for the element |
| 35 |
|
|
* @param bool required - is this a required element |
| 36 |
|
|
* @param int required - element width in characters, pixels (px), percentage (%) or elements (em) |
| 37 |
|
|
* @param int required - maximum number of chars allowed to type in |
| 38 |
|
|
*/ |
| 39 |
jonen |
1.3 |
function FEText($label, $required = FALSE, $width = NULL, $maxlength = NULL) { |
| 40 |
jonen |
1.1 |
$this->FormElement($label, $required); |
| 41 |
|
|
|
| 42 |
|
|
if ($width != NULL) { |
| 43 |
|
|
if (is_numeric($width)) |
| 44 |
|
|
$this->set_attribute("size", $width); |
| 45 |
|
|
else |
| 46 |
|
|
$this->set_style_attribute("width", $width); |
| 47 |
|
|
} |
| 48 |
|
|
|
| 49 |
|
|
if ($maxlength != NULL) |
| 50 |
|
|
$this->set_attribute("maxlength", $maxlength); |
| 51 |
|
|
} |
| 52 |
|
|
|
| 53 |
|
|
|
| 54 |
|
|
/** |
| 55 |
|
|
* This function builds and returns the |
| 56 |
|
|
* form element object |
| 57 |
|
|
* |
| 58 |
|
|
* @return object |
| 59 |
|
|
*/ |
| 60 |
|
|
function get_element() { |
| 61 |
|
|
|
| 62 |
|
|
$attributes = $this->_build_element_attributes(); |
| 63 |
|
|
$attributes["type"] = "text"; |
| 64 |
|
|
|
| 65 |
|
|
if (($value = $this->get_value()) != NULL) |
| 66 |
|
|
$attributes["value"] = $value; |
| 67 |
|
|
|
| 68 |
jonen |
1.2 |
return new INPUTtag($attributes); |
| 69 |
jonen |
1.1 |
} |
| 70 |
|
|
} |
| 71 |
|
|
|
| 72 |
|
|
/** |
| 73 |
|
|
* This is the Name FormElement which builds a |
| 74 |
|
|
* text input field, and validates against the |
| 75 |
|
|
* is_name() method. |
| 76 |
|
|
* |
| 77 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 78 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
| 79 |
|
|
* @package phpHtmlLib |
| 80 |
|
|
* @subpackage FormProcessing |
| 81 |
|
|
* |
| 82 |
|
|
* @copyright LGPL - See LICENCE |
| 83 |
|
|
*/ |
| 84 |
|
|
class FEName extends FEText { |
| 85 |
|
|
|
| 86 |
|
|
/** |
| 87 |
|
|
* This method validates the data |
| 88 |
|
|
* for this Form Element. |
| 89 |
|
|
* |
| 90 |
|
|
* It validates as is_name(). |
| 91 |
jonen |
1.2 |
* @param FormValidation object. |
| 92 |
jonen |
1.1 |
*/ |
| 93 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
| 94 |
|
|
if (!$_FormValidation->is_name($this->get_value())) { |
| 95 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 96 |
jonen |
1.1 |
return FALSE; |
| 97 |
|
|
} |
| 98 |
|
|
return TRUE; |
| 99 |
|
|
} |
| 100 |
|
|
} |
| 101 |
|
|
|
| 102 |
|
|
/** |
| 103 |
|
|
* This is the Email FormElement which builds a |
| 104 |
|
|
* text input field. |
| 105 |
|
|
* It validatest he data as is_email() |
| 106 |
|
|
* |
| 107 |
|
|
* |
| 108 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 109 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
| 110 |
|
|
* @package phpHtmlLib |
| 111 |
|
|
* @subpackage FormProcessing |
| 112 |
|
|
* |
| 113 |
|
|
* @copyright LGPL - See LICENCE |
| 114 |
|
|
*/ |
| 115 |
|
|
class FEEmail extends FEText { |
| 116 |
jonen |
1.4 |
|
| 117 |
|
|
/** Holds the flag to indicate |
| 118 |
|
|
* whether we allow email in |
| 119 |
|
|
* the long name format like |
| 120 |
|
|
* Foo Bar <email@email.com> |
| 121 |
|
|
*/ |
| 122 |
|
|
var $_allow_name = true; |
| 123 |
jonen |
1.1 |
|
| 124 |
|
|
/** |
| 125 |
|
|
* This method validates the data |
| 126 |
|
|
* for this Form Element. |
| 127 |
|
|
* |
| 128 |
|
|
* It validates as is_email(). |
| 129 |
jonen |
1.2 |
* @param FormValidation object. |
| 130 |
jonen |
1.1 |
*/ |
| 131 |
jonen |
1.2 |
function validate($_FormValidation) { |
| 132 |
jonen |
1.4 |
if (!$_FormValidation->is_email($this->get_value(), $this->_allow_name)) { |
| 133 |
jonen |
1.2 |
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 134 |
jonen |
1.1 |
return FALSE; |
| 135 |
|
|
} |
| 136 |
|
|
return TRUE; |
| 137 |
|
|
} |
| 138 |
jonen |
1.4 |
|
| 139 |
|
|
/** |
| 140 |
|
|
* Sets the flag to indicate |
| 141 |
|
|
* whether we allow email in |
| 142 |
|
|
* the long name format like |
| 143 |
|
|
* Foo Bar <email@email.com> |
| 144 |
|
|
* |
| 145 |
|
|
* @param bool |
| 146 |
|
|
*/ |
| 147 |
|
|
function set_allow_name($flag) { |
| 148 |
|
|
$this->_allow_name = $flag; |
| 149 |
|
|
} |
| 150 |
jonen |
1.1 |
} |
| 151 |
|
|
|
| 152 |
|
|
/** |
| 153 |
|
|
* This is the EmailMany FormElement which builds a |
| 154 |
|
|
* text input field. This allows for multiple email |
| 155 |
|
|
* addresses in 1 text input field seperated by commas. |
| 156 |
|
|
* |
| 157 |
|
|
* It validatest he data as is_manyemails() |
| 158 |
|
|
* |
| 159 |
|
|
* |
| 160 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 161 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
| 162 |
|
|
* @package phpHtmlLib |
| 163 |
|
|
* @subpackage FormProcessing |
| 164 |
|
|
* |
| 165 |
|
|
* @copyright LGPL - See LICENCE |
| 166 |
|
|
*/ |
| 167 |
|
|
class FEEmailMany extends FEText { |
| 168 |
|
|
|
| 169 |
|
|
/** |
| 170 |
|
|
* This method validates the data |
| 171 |
|
|
* for this Form Element. |
| 172 |
|
|
* |
| 173 |
|
|
* It validates as is_manyemails(). |
| 174 |
jonen |
1.2 |
* @param FormValidation object. |
| 175 |
jonen |
1.1 |
*/ |
| 176 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
| 177 |
|
|
if (!$_FormValidation->is_manyemails($this->get_value())) { |
| 178 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 179 |
jonen |
1.1 |
return FALSE; |
| 180 |
|
|
} |
| 181 |
|
|
return TRUE; |
| 182 |
|
|
} |
| 183 |
|
|
} |
| 184 |
|
|
|
| 185 |
|
|
/** |
| 186 |
|
|
* This is the DomainName FormElement which builds a |
| 187 |
|
|
* text input field. |
| 188 |
|
|
* It validates as is_domainname(). |
| 189 |
|
|
* |
| 190 |
|
|
* |
| 191 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 192 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
| 193 |
|
|
* @package phpHtmlLib |
| 194 |
|
|
* @subpackage FormProcessing |
| 195 |
|
|
* |
| 196 |
|
|
* @copyright LGPL - See LICENCE |
| 197 |
|
|
*/ |
| 198 |
|
|
class FEDomainName extends FEText { |
| 199 |
|
|
|
| 200 |
|
|
/** |
| 201 |
|
|
* This method validates the data |
| 202 |
|
|
* for this Form Element. |
| 203 |
|
|
* |
| 204 |
|
|
* It validates as is_domainname(). |
| 205 |
jonen |
1.2 |
* @param FormValidation object. |
| 206 |
jonen |
1.1 |
*/ |
| 207 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
| 208 |
|
|
if (!$_FormValidation->is_domainname($this->get_value())) { |
| 209 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 210 |
jonen |
1.1 |
return FALSE; |
| 211 |
|
|
} |
| 212 |
|
|
return TRUE; |
| 213 |
|
|
} |
| 214 |
|
|
} |
| 215 |
|
|
|
| 216 |
|
|
/** |
| 217 |
jonen |
1.2 |
* This is the DomainName FormElement which builds a |
| 218 |
|
|
* text input field. It also includes a port # |
| 219 |
|
|
* It validates as is_domainname(). |
| 220 |
jonen |
1.1 |
* |
| 221 |
|
|
* |
| 222 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 223 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
| 224 |
|
|
* @package phpHtmlLib |
| 225 |
|
|
* @subpackage FormProcessing |
| 226 |
|
|
* |
| 227 |
|
|
* @copyright LGPL - See LICENCE |
| 228 |
|
|
*/ |
| 229 |
jonen |
1.2 |
class FEHostNameWithPort extends FEText { |
| 230 |
|
|
|
| 231 |
|
|
/** |
| 232 |
|
|
* flag to tell us to seperate the port |
| 233 |
|
|
* value into it's own field |
| 234 |
|
|
*/ |
| 235 |
|
|
var $_seperate_port_flag = FALSE; |
| 236 |
|
|
|
| 237 |
|
|
/** |
| 238 |
|
|
* The constructor |
| 239 |
|
|
* |
| 240 |
|
|
* @param label string - text label for the element |
| 241 |
|
|
* @param bool required - is this a required element |
| 242 |
|
|
* @param int required - element width in characters, pixels (px), percentage (%) or elements (em) |
| 243 |
|
|
* @param int required - maximum number of chars allowed to type in |
| 244 |
|
|
* @param bool optional - seperate the port value into it's own textarea field |
| 245 |
|
|
*/ |
| 246 |
|
|
function FEHostNameWithPort($label, $required = TRUE, $width = NULL, $maxlength = NULL, |
| 247 |
|
|
$seperate_port=FALSE) { |
| 248 |
|
|
$this->FEText($label, $required, $width, $maxlength); |
| 249 |
|
|
$this->_seperate_port_flag = $seperate_port; |
| 250 |
|
|
} |
| 251 |
|
|
|
| 252 |
|
|
/** |
| 253 |
|
|
* This function builds and returns the |
| 254 |
|
|
* form element object |
| 255 |
|
|
* |
| 256 |
|
|
* @return object |
| 257 |
|
|
*/ |
| 258 |
|
|
function get_element() { |
| 259 |
|
|
$host_attributes = $this->_build_element_attributes(); |
| 260 |
|
|
$host_attributes["type"] = "text"; |
| 261 |
|
|
|
| 262 |
|
|
$element_name = $this->get_element_name(); |
| 263 |
|
|
$host_value = $this->get_value(); |
| 264 |
|
|
|
| 265 |
|
|
if ($this->_seperate_port_flag) { |
| 266 |
|
|
$host_attributes["name"] = $element_name."[0]"; |
| 267 |
|
|
if ($host_value != NULL && !is_array($host_value)) { |
| 268 |
|
|
$host_value = explode(":", $host_value ); |
| 269 |
|
|
$host_attributes["value"] = $host_value[0]; |
| 270 |
|
|
} else if (is_array($host_value)) { |
| 271 |
|
|
$host_attributes["value"] = $host_value[0]; |
| 272 |
|
|
} |
| 273 |
|
|
|
| 274 |
|
|
$port_attributes = $host_attributes; |
| 275 |
|
|
$port_attributes["name"] = $element_name."[1]"; |
| 276 |
|
|
$port_attributes["size"] = 10; |
| 277 |
|
|
$port_attributes["maxlenght"] = 5; |
| 278 |
|
|
if (@array_key_exists("0", $host_value)) { |
| 279 |
|
|
$port_attributes["value"] = $host_value[1]; |
| 280 |
|
|
} |
| 281 |
|
|
|
| 282 |
|
|
$port_label = html_span("formlabel", "Port"); |
| 283 |
|
|
if ($this->has_error("Port")) { |
| 284 |
|
|
$port_label->set_tag_attribute("style","color:red;"); |
| 285 |
|
|
} |
| 286 |
|
|
|
| 287 |
|
|
return container( new INPUTtag($host_attributes), |
| 288 |
|
|
$port_label, |
| 289 |
|
|
new INPUTtag($port_attributes)); |
| 290 |
|
|
} else { |
| 291 |
|
|
if ($host_value != NULL) { |
| 292 |
|
|
$host_attributes["value"] = $host_value; |
| 293 |
|
|
} |
| 294 |
|
|
return new INPUTtag($host_attributes); |
| 295 |
|
|
} |
| 296 |
|
|
} |
| 297 |
jonen |
1.1 |
|
| 298 |
|
|
/** |
| 299 |
|
|
* This method validates the data |
| 300 |
|
|
* for this Form Element. |
| 301 |
|
|
* |
| 302 |
jonen |
1.2 |
* It validates as is_domainname(). |
| 303 |
|
|
* @param FormValidation object. |
| 304 |
jonen |
1.1 |
*/ |
| 305 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
| 306 |
|
|
$value = $this->get_value(); |
| 307 |
|
|
if (!is_array($value)) { |
| 308 |
|
|
$value = explode(":", $value); |
| 309 |
|
|
} |
| 310 |
|
|
|
| 311 |
|
|
$valid = $this->_validate_hostname($_FormValidation, $value[0]); |
| 312 |
|
|
|
| 313 |
|
|
//now validate the port |
| 314 |
|
|
if ($value[1] != NULL) { |
| 315 |
|
|
if (!$_FormValidation->is_number($value[1])) { |
| 316 |
|
|
if ($this->_seperate_port_flag) { |
| 317 |
|
|
$this->set_error_message($_FormValidation->get_error_message(), "Port"); |
| 318 |
|
|
} else { |
| 319 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 320 |
|
|
} |
| 321 |
|
|
$value = FALSE; |
| 322 |
|
|
} |
| 323 |
|
|
|
| 324 |
|
|
//make sure the hostname isn't null |
| 325 |
|
|
if ($value[0] == NULL) { |
| 326 |
|
|
//we have an error here because |
| 327 |
|
|
//they entered a port w/o a hostname |
| 328 |
|
|
$_FormValidation->_error("", "This field cannot be empty, if the Port is filled out"); |
| 329 |
|
|
$this->set_error_message($_FormValidation->get_error_message()); |
| 330 |
|
|
} |
| 331 |
|
|
} |
| 332 |
|
|
return $valid; |
| 333 |
|
|
} |
| 334 |
|
|
|
| 335 |
|
|
|
| 336 |
|
|
/** |
| 337 |
|
|
* this validates the hostname field only |
| 338 |
|
|
* |
| 339 |
|
|
* @return bool TRUE = valid |
| 340 |
|
|
*/ |
| 341 |
|
|
function _validate_hostname(&$_FormValidation, $value) { |
| 342 |
|
|
$valid = TRUE; |
| 343 |
|
|
//validate the hostname |
| 344 |
|
|
if ($value != NULL && !$_FormValidation->is_hostname($value)) { |
| 345 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 346 |
|
|
$valid = FALSE; |
| 347 |
jonen |
1.1 |
} |
| 348 |
jonen |
1.2 |
|
| 349 |
|
|
return $valid; |
| 350 |
jonen |
1.1 |
} |
| 351 |
|
|
} |
| 352 |
|
|
|
| 353 |
|
|
/** |
| 354 |
jonen |
1.2 |
* This is the Ip Address FormElement which builds a |
| 355 |
jonen |
1.1 |
* text input field. |
| 356 |
jonen |
1.2 |
* It validates as is_ip(). |
| 357 |
jonen |
1.1 |
* |
| 358 |
|
|
* |
| 359 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 360 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
| 361 |
|
|
* @package phpHtmlLib |
| 362 |
|
|
* @subpackage FormProcessing |
| 363 |
|
|
* |
| 364 |
|
|
* @copyright LGPL - See LICENCE |
| 365 |
|
|
*/ |
| 366 |
jonen |
1.2 |
class FEIPAddress extends FEText { |
| 367 |
jonen |
1.1 |
|
| 368 |
|
|
/** |
| 369 |
|
|
* This method validates the data |
| 370 |
|
|
* for this Form Element. |
| 371 |
|
|
* |
| 372 |
jonen |
1.2 |
* It validates as is_ip(). |
| 373 |
|
|
* @param FormValidation object. |
| 374 |
jonen |
1.1 |
*/ |
| 375 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
| 376 |
|
|
if (!$_FormValidation->is_ip($this->get_value())) { |
| 377 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 378 |
jonen |
1.1 |
return FALSE; |
| 379 |
|
|
} |
| 380 |
|
|
return TRUE; |
| 381 |
|
|
} |
| 382 |
|
|
} |
| 383 |
|
|
|
| 384 |
|
|
/** |
| 385 |
jonen |
1.2 |
* This is the Ip Address FormElement which builds a |
| 386 |
jonen |
1.1 |
* text input field. |
| 387 |
jonen |
1.2 |
* It validates as is_ip(). |
| 388 |
jonen |
1.1 |
* |
| 389 |
|
|
* |
| 390 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 391 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
| 392 |
|
|
* @package phpHtmlLib |
| 393 |
|
|
* @subpackage FormProcessing |
| 394 |
|
|
* |
| 395 |
|
|
* @copyright LGPL - See LICENCE |
| 396 |
|
|
*/ |
| 397 |
jonen |
1.2 |
class FEIPAddressWithPort extends FEHostNameWithPort { |
| 398 |
jonen |
1.1 |
|
| 399 |
|
|
/** |
| 400 |
jonen |
1.2 |
* this validates the hostname field only |
| 401 |
|
|
* |
| 402 |
|
|
* @return bool TRUE = valid |
| 403 |
|
|
*/ |
| 404 |
|
|
function _validate_hostname(&$_FormValidation, $value) { |
| 405 |
|
|
$valid = TRUE; |
| 406 |
|
|
//validate the hostname |
| 407 |
|
|
if ($value != NULL && !$_FormValidation->is_ip($value)) { |
| 408 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 409 |
|
|
$valid = FALSE; |
| 410 |
jonen |
1.1 |
} |
| 411 |
jonen |
1.2 |
return $valid; |
| 412 |
jonen |
1.1 |
} |
| 413 |
|
|
} |
| 414 |
|
|
|
| 415 |
jonen |
1.2 |
|
| 416 |
|
|
|
| 417 |
jonen |
1.1 |
/** |
| 418 |
|
|
* This is the URL FormElement which builds a |
| 419 |
|
|
* text input field. |
| 420 |
|
|
* It validates as is_url(). |
| 421 |
|
|
* |
| 422 |
|
|
* |
| 423 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 424 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
| 425 |
|
|
* @package phpHtmlLib |
| 426 |
|
|
* @subpackage FormProcessing |
| 427 |
|
|
* |
| 428 |
|
|
* @copyright LGPL - See LICENCE |
| 429 |
|
|
*/ |
| 430 |
|
|
class FEUrl extends FEText { |
| 431 |
|
|
|
| 432 |
|
|
/** |
| 433 |
|
|
* This method validates the data |
| 434 |
|
|
* for this Form Element. |
| 435 |
|
|
* |
| 436 |
|
|
* It validates as is_url(). |
| 437 |
jonen |
1.2 |
* @param FormValidation object. |
| 438 |
jonen |
1.1 |
*/ |
| 439 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
| 440 |
|
|
if (!$_FormValidation->is_url($this->get_value())) { |
| 441 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 442 |
jonen |
1.1 |
return FALSE; |
| 443 |
|
|
} |
| 444 |
|
|
return TRUE; |
| 445 |
|
|
} |
| 446 |
|
|
} |
| 447 |
|
|
|
| 448 |
|
|
/** |
| 449 |
|
|
* This is the URLStrict FormElement which builds a |
| 450 |
|
|
* text input field. |
| 451 |
|
|
* This is the same as FEUrl, but it requires the http:// |
| 452 |
|
|
* It validates as is_strict_url(). |
| 453 |
|
|
* |
| 454 |
|
|
* |
| 455 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 456 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
| 457 |
|
|
* @package phpHtmlLib |
| 458 |
|
|
* @subpackage FormProcessing |
| 459 |
|
|
* |
| 460 |
|
|
* @copyright LGPL - See LICENCE |
| 461 |
|
|
*/ |
| 462 |
|
|
class FEUrlStrict extends FEText { |
| 463 |
|
|
|
| 464 |
|
|
/** |
| 465 |
|
|
* This method validates the data |
| 466 |
|
|
* for this Form Element. |
| 467 |
|
|
* |
| 468 |
|
|
* It validates as is_strict_url(). |
| 469 |
jonen |
1.2 |
* @param FormValidation object. |
| 470 |
jonen |
1.1 |
*/ |
| 471 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
| 472 |
|
|
if (!$_FormValidation->is_strict_url($this->get_value())) { |
| 473 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 474 |
jonen |
1.3 |
return FALSE; |
| 475 |
|
|
} |
| 476 |
|
|
return TRUE; |
| 477 |
|
|
} |
| 478 |
|
|
} |
| 479 |
|
|
|
| 480 |
|
|
/** |
| 481 |
|
|
* This is the FEZipcode class. |
| 482 |
|
|
* |
| 483 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
| 484 |
jonen |
1.3 |
*/ |
| 485 |
|
|
class FEZipcode extends FEText { |
| 486 |
|
|
/** |
| 487 |
|
|
* The constructor |
| 488 |
|
|
* |
| 489 |
|
|
* @param label string - text label for the element |
| 490 |
|
|
* @param bool required - is this a required element |
| 491 |
|
|
* @param int required - element width in characters, pixels (px), percentage (%) or elements (em) |
| 492 |
|
|
* @param int required - maximum number of chars allowed to type in |
| 493 |
|
|
*/ |
| 494 |
|
|
function FEZipcode($label, $required=false, $width = NULL, $maxlength = 5) { |
| 495 |
|
|
$this->FEText($label, $required, $width, $maxlength); |
| 496 |
|
|
} |
| 497 |
|
|
|
| 498 |
|
|
|
| 499 |
|
|
/** |
| 500 |
|
|
* This method validates the data |
| 501 |
|
|
* for this Form Element. |
| 502 |
|
|
* |
| 503 |
|
|
* It validates as is_name(). |
| 504 |
|
|
* @param FormValidation object. |
| 505 |
|
|
*/ |
| 506 |
|
|
function validate(&$_FormValidation) { |
| 507 |
|
|
if (!$_FormValidation->is_zip($this->get_value())) { |
| 508 |
|
|
$this->set_error_message( $_FormValidation->get_error_message() ); |
| 509 |
|
|
return FALSE; |
| 510 |
|
|
} |
| 511 |
|
|
return TRUE; |
| 512 |
|
|
} |
| 513 |
|
|
} |
| 514 |
|
|
|
| 515 |
|
|
/** |
| 516 |
jonen |
1.4 |
* This is the RegEx FormElement which builds a text input field, and validates |
| 517 |
|
|
* against the is_regex() method. |
| 518 |
|
|
* |
| 519 |
|
|
* Example as it would appear in FormContent::form_init_elements(): |
| 520 |
|
|
* <code> |
| 521 |
|
|
* $this->add_element( new FERegEx("FERegEx label", false, '200px', 3, '/^pattern to match$/', 'error message when pattern does not match') ); |
| 522 |
|
|
* </code> |
| 523 |
jonen |
1.3 |
* |
| 524 |
|
|
* @author Culley Harrelson <culley@fastmail.fm> |
| 525 |
|
|
* @package phpHtmlLib |
| 526 |
|
|
* @subpackage FormProcessing |
| 527 |
|
|
* |
| 528 |
|
|
* @copyright LGPL - See LICENCE |
| 529 |
|
|
*/ |
| 530 |
|
|
class FERegEx extends FEText { |
| 531 |
|
|
|
| 532 |
|
|
var $_regex; |
| 533 |
|
|
var $_error_message; |
| 534 |
|
|
|
| 535 |
|
|
/** |
| 536 |
|
|
* The constructor |
| 537 |
|
|
* |
| 538 |
|
|
* @param label string - text label for the element |
| 539 |
|
|
* @param required bool- is this a required element |
| 540 |
|
|
* @param width int - element width in characters, pixels (px), percentage (%) or elements (em) |
| 541 |
|
|
* @param maxlength int- maximum number of chars allowed to type in |
| 542 |
|
|
* @param regex string - a valid regular expression i.e. '/[a-z]+$/i' |
| 543 |
|
|
* @param error_message string - error message for failure to match the regex |
| 544 |
|
|
*/ |
| 545 |
|
|
function FERegEx($label, $required=false, $width = NULL, $maxlength = NULL, $regex, $error_message) { |
| 546 |
|
|
$this->FEText($label, $required, $width, $maxlength); |
| 547 |
|
|
$this->_regex = $regex; |
| 548 |
|
|
$this->_error_message = $error_message; |
| 549 |
|
|
} |
| 550 |
|
|
|
| 551 |
|
|
/** |
| 552 |
|
|
* This method validates the data |
| 553 |
|
|
* for this Form Element. |
| 554 |
|
|
* |
| 555 |
|
|
* It validates as is_regex(). |
| 556 |
|
|
* @param FormValidation object. |
| 557 |
jonen |
1.4 |
* @return boolean |
| 558 |
jonen |
1.3 |
*/ |
| 559 |
|
|
function validate(&$_FormValidation) { |
| 560 |
|
|
if (!$_FormValidation->is_regex($this->_regex, $this->get_value())) { |
| 561 |
|
|
$this->set_error_message( $this->_error_message ); |
| 562 |
jonen |
1.1 |
return FALSE; |
| 563 |
|
|
} |
| 564 |
|
|
return TRUE; |
| 565 |
|
|
} |
| 566 |
|
|
} |
| 567 |
|
|
?> |