/** * Construct a CSRF guard hidden field. You should provide the name of the csrf guard as second parameter here. * @param jWidget $Parent */ function __construct(jWidget $Parent, $Name) { $this->__setname($Name); parent::__construct($Parent); $this->SetValidation(function ($Data) use($Name) { return jf::LoadSessionSetting(jFormCsrf::SettingNamePrefix . $Name) == $Data; }); }
function SetValidation($Validation) { if (is_string($Validation) and preg_match($Validation, "") !== false) { $res = str_replace("\\", "\\\\", $Validation); $res = str_replace("'", "\\'", $res); $this->JavascriptValidation = $res; //regexp } parent::SetValidation($Validation); }
/** * Construct a Captcha Field. * @param jWidget $Parent */ function __construct(jWidget $Parent) { parent::__construct($Parent, "CAPTCHA"); if (isset($_GET['CAPTCHA']) && $_GET['CAPTCHA'] == $this->Name()) { $this->DumpImage(); } $obj = $this; $this->SetValidation(function ($Data) use($obj) { return $obj->Validate($Data); }); }
/** * Construct a radio button set * @param jWidget $Parent * @param string $Label * @param array $Items the first element is the default one. If keys are omitted, values serve as both text and data of options. */ function __construct(jWidget $Parent, $Label = null, array $Items) { parent::__construct($Parent, $Label); $this->Items = $Items; $IsAssoc = $this->IsAssociative($Items); $this->SetValidation(function ($Data) use($Items, $IsAssoc) { if ($IsAssoc) { return isset($Items[$Data]); } else { return in_array($Data, $Items); } }); }
/** * * Note: you should explicitly call Put method of this object to put the uploaded file * @param jWidget $Parent * @param string $Label * @param string $Location where to put uploaded file * @param string $MaxSize * */ function __construct(jWidget $Parent, $Label = null, $MaxSize = null) { parent::__construct($Parent, $Label); $this->MaxSize = $MaxSize; $Name = $this->Name(); $this->SetValidation(function ($Data) use($MaxSize, $Name) { if (!isset($_FILES[$Name])) { return false; } $file = $_FILES[$Name]; if ($file["error"] > 0) { return $file['error']; } if ($MaxSize !== null && $file['size'] > $this->MaxSize) { return UPLOAD_ERR_FORM_SIZE; } return file_exists($file['tmp_name']); }); }
function __construct($Parent, $Label) { parent::__construct($Parent, $Label); $this->SetValue($Label); }