本文整理汇总了PHP中RequiredFields::php方法的典型用法代码示例。如果您正苦于以下问题:PHP RequiredFields::php方法的具体用法?PHP RequiredFields::php怎么用?PHP RequiredFields::php使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequiredFields
的用法示例。
在下文中一共展示了RequiredFields::php方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: php
/**
* Currently not used
*
* TODO could use this to validate variations etc. perhaps
*
* @param Array $data Submitted data
* @return Boolean Returns TRUE if the submitted data is valid, otherwise FALSE.
*/
function php($data)
{
$valid = parent::php($data);
//$this->validationError("", "This is a test error message for the Title.", 'bad');
//$valid = false;
return $valid;
}
示例2: php
public function php($data)
{
$member = $this->member;
$valid = true;
foreach ($this->unique as $field) {
$other = DataObject::get_one('Member', sprintf('"%s" = \'%s\'', Convert::raw2sql($field), Convert::raw2sql($data[$field])));
if ($other && (!$this->member || !$this->member->exists() || $other->ID != $this->member->ID)) {
$fieldInstance = $this->form->Fields()->dataFieldByName($field);
if ($fieldInstance->getCustomValidationMessage()) {
$message = $fieldInstance->getCustomValidationMessage();
} else {
$message = sprintf(_t('MemberProfiles.MEMBERWITHSAME', 'There is already a member with the same %s.'), $field);
}
$valid = false;
$this->validationError($field, $message, 'required');
}
}
// Create a dummy member as this is required for custom password validators
if (isset($data['Password']) && $data['Password'] !== "") {
if (is_null($member)) {
$member = Member::create();
}
if ($validator = $member::password_validator()) {
$results = $validator->validate($data['Password'], $member);
if (!$results->valid()) {
$valid = false;
foreach ($results->messageList() as $key => $value) {
$this->validationError('Password', $value, 'required');
}
}
}
}
return $valid && parent::php($data);
}
示例3: php
/**
* Check that an {@link Attribute} Title is unique.
*
* @param Array $data Submitted data
* @return Boolean Returns TRUE if the submitted data is valid, otherwise FALSE.
*/
function php($data)
{
$valid = parent::php($data);
$newTitle = isset($data['Title']) ? $data['Title'] : null;
if ($newTitle) {
$existingTitles = DataObject::get('Attribute');
$existingTitles = $existingTitles->map('ID', 'Title');
if (isset($data['ID'])) {
unset($existingTitles[$data['ID']]);
}
if (in_array($newTitle, $existingTitles)) {
$valid = false;
$this->validationError("Title", "Title already exists, please choose a different one.", 'bad');
}
}
/*
//If invalid tidy up empty Attributes in the DB
if (!$valid) {
$emptyAttributes = DataObject::get(
'Attribute',
'"Attribute"."Title" IS NULL AND "Attribute"."Label" IS NULL'
);
if ($emptyAttributes && $emptyAttributes->exists()) foreach ($emptyAttributes as $attr) {
$attr->delete();
}
}
*/
return $valid;
}
示例4: php
function php($data)
{
$valid = parent::php($data);
// if we are in a complex table field popup, use ctf[childID], else use ID
if (isset($_REQUEST['ctf']['childID'])) {
$id = $_REQUEST['ctf']['childID'];
} else {
$id = $this->form->record->ID;
}
if (isset($id)) {
if (isset($_REQUEST['ctf']['ClassName'])) {
$class = $_REQUEST['ctf']['ClassName'];
} else {
$class = $this->form->record->class;
}
$object = $class::get()->byId($id);
if ($object) {
foreach ($this->required_files_fields as $key => $value) {
$key = is_string($key) ? $key : $value;
$fileId = $object->{$key}()->ID;
if (!$fileId) {
$name = isset($value) && is_array($value) && array_key_exists('Name', $value) ? $value['Name'] : $key;
$errorMessage = sprintf(_t('Form.FIELDISREQUIRED', '%s is required') . '.', strip_tags('"' . $name . '"'));
$this->validationError($key, $errorMessage, "required");
$valid = false;
break;
}
}
}
}
return $valid;
}
示例5: php
public function php($data)
{
if (!parent::php($data)) {
return false;
}
// Skip unsaved records
if (empty($data['ID']) || !is_numeric($data['ID'])) {
return true;
}
$fields = EditableFormField::get()->filter('ParentID', $data['ID'])->sort('"Sort" ASC');
// Current nesting
$stack = array();
$conditionalStep = false;
// Is the current step conditional?
foreach ($fields as $field) {
if ($field instanceof EditableFormStep) {
// Page at top level, or after another page is ok
if (empty($stack) || count($stack) === 1 && $stack[0] instanceof EditableFormStep) {
$stack = array($field);
$conditionalStep = $field->DisplayRules()->count() > 0;
continue;
}
$this->validationError('FormFields', _t("UserFormValidator.UNEXPECTED_BREAK", "Unexpected page break '{name}' inside nested field '{group}'", array('name' => $field->CMSTitle, 'group' => end($stack)->CMSTitle)), 'error');
return false;
}
// Validate no pages
if (empty($stack)) {
$this->validationError('FormFields', _t("UserFormValidator.NO_PAGE", "Field '{name}' found before any pages", array('name' => $field->CMSTitle)), 'error');
return false;
}
// Nest field group
if ($field instanceof EditableFieldGroup) {
$stack[] = $field;
continue;
}
// Unnest field group
if ($field instanceof EditableFieldGroupEnd) {
$top = end($stack);
// Check that the top is a group at all
if (!$top instanceof EditableFieldGroup) {
$this->validationError('FormFields', _t("UserFormValidator.UNEXPECTED_GROUP_END", "'{name}' found without a matching group", array('name' => $field->CMSTitle)), 'error');
return false;
}
// Check that the top is the right group
if ($top->EndID != $field->ID) {
$this->validationError('FormFields', _t("UserFormValidator.WRONG_GROUP_END", "'{name}' found closes the wrong group '{group}'", array('name' => $field->CMSTitle, 'group' => $top->CMSTitle)), 'error');
return false;
}
// Unnest group
array_pop($stack);
}
// Normal field type
if ($conditionalStep && $field->Required) {
$this->validationError('FormFields', _t("UserFormValidator.CONDITIONAL_REQUIRED", "Required field '{name}' cannot be placed within a conditional page", array('name' => $field->CMSTitle)), 'error');
return false;
}
}
return true;
}
示例6: php
public function php($data)
{
$valid = parent::php($data);
if ($valid && !$this->form->getBuyable($_POST)) {
$this->validationError("", "This product is not available with the selected options.");
$valid = false;
}
return $valid;
}
示例7: php
public function php($data)
{
$valid = parent::php($data);
if ($valid && !$this->form->getBuyable($_POST)) {
$this->validationError("", _t('VariationForm.PRODUCT_NOT_AVAILABLE', "This product is not available with the selected options."));
$valid = false;
}
return $valid;
}
示例8: php
/**
* Check that current product variation is valid
*
* @param Array $data Submitted data
* @return Boolean Returns TRUE if the submitted data is valid, otherwise FALSE.
*/
function php($data)
{
$valid = parent::php($data);
$fields = $this->form->Fields();
//Check that variation exists if necessary
$form = $this->form;
$request = $this->form->getRequest();
//Get product variations from options sent
//TODO refactor this
$productVariations = new DataObjectSet();
$options = $request->postVar('Options');
$product = DataObject::get_by_id($data['ProductClass'], $data['ProductID']);
$variations = $product ? $product->Variations() : new DataObjectSet();
if ($variations && $variations->exists()) {
foreach ($variations as $variation) {
$variationOptions = $variation->Options()->map('AttributeID', 'ID');
if ($options == $variationOptions && $variation->isEnabled()) {
$productVariations->push($variation);
}
}
}
if ((!$productVariations || !$productVariations->exists()) && $product && $product->requiresVariation()) {
$this->form->sessionMessage(_t('Form.VARIATIONS_REQUIRED', 'This product requires options before it can be added to the cart.'), 'bad');
//Have to set an error for Form::validate()
$this->errors[] = true;
$valid = false;
return $valid;
}
//Validate that the product/variation being added is inStock()
$stockLevel = 0;
if ($product) {
if ($product->requiresVariation()) {
$stockLevel = $productVariations->First()->StockLevel()->Level;
} else {
$stockLevel = $product->StockLevel()->Level;
}
}
if ($stockLevel == 0) {
$this->form->sessionMessage(_t('Form.STOCK_LEVEL', ''), 'bad');
//Have to set an error for Form::validate()
$this->errors[] = true;
$valid = false;
}
//Validate the quantity is not greater than the available stock
$quantity = $request->postVar('Quantity');
if ($stockLevel > 0 && $stockLevel < $quantity) {
$this->form->sessionMessage(_t('Form.STOCK_LEVEL_MORE_THAN_QUANTITY', 'The quantity is greater than available stock for this product.'), 'bad');
//Have to set an error for Form::validate()
$this->errors[] = true;
$valid = false;
}
return $valid;
}
示例9: php
public function php($data)
{
$valid = parent::php($data);
$uniquefield = $this->uniquefield;
$organisation = Organisation::get()->filter($uniquefield, $data[$uniquefield])->first();
if ($uniquefield && is_object($organisation) && $organisation->isInDB()) {
$uniqueField = $this->form->Fields()->dataFieldByName($uniquefield);
$this->validationError($uniqueField->id(), sprintf(_t('Member.VALIDATIONORGANISATIONEXISTS', 'An organisation already exists with the same %s'), strtolower($uniquefield)), 'required');
$valid = false;
}
return $valid;
}
开发者ID:helpfulrobot,项目名称:burnbright-silverstripe-organisations,代码行数:12,代码来源:CreateOrganisationForm.php
示例10: php
/**
* Ensures member unique id stays unique.
*/
public function php($data)
{
$valid = parent::php($data);
$field = Member::get_unique_identifier_field();
if (isset($data[$field])) {
$uid = $data[Member::get_unique_identifier_field()];
$currentmember = Member::currentUser();
//can't be taken
if (DataObject::get_one('Member', "{$field} = '{$uid}' AND ID != " . $currentmember->ID)) {
$this->validationError($field, "\"{$uid}\" is already taken by another member. Try another.", "required");
$valid = false;
}
}
return $valid;
}
示例11: php
public function php($data)
{
$customValid = true;
$requiredValid = parent::php($data);
// If there's a custom validator set, validate with that too
if ($validatorClass = self::config()->custom_validator) {
$custom = new $validatorClass();
$custom->setForm($this->form);
$customValid = $custom->php($data);
if (!$customValid) {
if ($requiredValid) {
$this->errors = array();
}
$this->errors = array_merge($this->errors, $custom->errors);
}
}
return $customValid && $requiredValid;
}
示例12: php
public function php($data)
{
$member = $this->member;
$valid = true;
foreach ($this->unique as $field) {
$other = DataObject::get_one('Member', sprintf('"%s" = \'%s\'', Convert::raw2sql($field), Convert::raw2sql($data[$field])));
if ($other && (!$this->member || !$this->member->exists() || $other->ID != $this->member->ID)) {
$fieldInstance = $this->form->dataFieldByName($field);
if ($fieldInstance->getCustomValidationMessage()) {
$message = $fieldInstance->getCustomValidationMessage();
} else {
$message = sprintf(_t('MemberProfiles.MEMBERWITHSAME', 'There is already a member with the same %s.'), $field);
}
$valid = false;
$this->validationError($field, $message, 'required');
}
}
return $valid && parent::php($data);
}
示例13: php
public function php($data)
{
$valid = parent::php($data);
if ($valid) {
$controller = $this->form->Controller();
if ($controller->VariableAmount) {
$giftvalue = $data['UnitPrice'];
if ($controller->MinimumAmount > 0 && $giftvalue < $controller->MinimumAmount) {
$this->validationError("UnitPrice", "Gift value must be at least " . $controller->MinimumAmount);
return false;
}
if ($giftvalue <= 0) {
$this->validationError("UnitPrice", "Gift value must be greater than 0");
return false;
}
}
}
return $valid;
}
示例14: php
public function php($data)
{
$valid = parent::php($data);
$this->setData($data);
// Fetch any extended validation routines on the caller
$extended = $this->getExtendedValidationRoutines();
// Only deal-to extended routines once the parent is done
if ($valid && $extended['fieldValid'] !== true) {
$fieldName = $extended['fieldName'];
$formField = $extended['fieldField'];
$errorMessage = sprintf($extended['fieldMsg'], strip_tags('"' . ($formField && $formField->Title() ? $formField->Title() : $fieldName) . '"'));
if ($formField && ($msg = $formField->getCustomValidationMessage())) {
$errorMessage = $msg;
}
$this->validationError($fieldName, $errorMessage, "required");
$valid = false;
}
return $valid;
}
示例15: php
public function php($data)
{
$valid = parent::php($data);
//do component validation
try {
$this->config->validateData($data);
} catch (ValidationException $e) {
$result = $e->getResult();
foreach ($result->messageList() as $fieldname => $message) {
if (!$this->fieldHasError($fieldname)) {
$this->validationError($fieldname, $message, 'bad');
}
}
$valid = false;
}
if (!$valid) {
$this->form->sessionMessage(_t("CheckoutComponentValidator.InvalidDataMessage", "There are problems with the data you entered. See below:"), "bad");
}
return $valid;
}