/**
  * 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;
 }
 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);
 }
 /**
  * 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;
 }
 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;
 }
 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;
 }
 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;
 }
 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;
 }
 /**
  * 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;
 }
 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;
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
 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;
 }
 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);
 }
 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;
 }
Ejemplo n.º 14
0
 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;
 }
 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;
 }
 public function php($data)
 {
     if (!parent::php($data)) {
         return false;
     }
     // Skip unsaved records
     if (!$this->record || !$this->record->exists()) {
         return true;
     }
     // Skip validation if not required
     if (empty($data['Required'])) {
         return;
     }
     // Skip validation if no rules
     $count = EditableCustomRule::get()->filter('ParentID', $this->record->ID)->count();
     if ($count == 0) {
         return true;
     }
     // Both required = true and rules > 0 should error
     $this->validationError('Required_Error', _t("EditableFormFieldValidator.REQUIRED_ERROR", "Form fields cannot be required and have conditional display rules."), 'error');
     return false;
 }
 /**
  * Check that current order is valid
  *
  * @param Array $data Submitted data
  * @return Boolean Returns TRUE if the submitted data is valid, otherwise FALSE.
  */
 function php($data)
 {
     //TODO move the form error messages to CheckoutForm::validate()
     $valid = parent::php($data);
     $fields = $this->form->Fields();
     //Check the order is valid
     $currentOrder = CartControllerExtension::get_current_order();
     if (!$currentOrder) {
         $this->form->sessionMessage(_t('Form.ORDER_IS_NOT_VALID', 'Your cart seems to be empty, please add an item from the shop'), 'bad');
         //Have to set an error for Form::validate()
         $this->errors[] = true;
         $valid = false;
     } else {
         $validation = $currentOrder->validateForCart();
         if (!$validation->valid()) {
             $this->form->sessionMessage(_t('Form.ORDER_IS_NOT_VALID', 'There seems to be a problem with your order. ' . $validation->message()), 'bad');
             //Have to set an error for Form::validate()
             $this->errors[] = true;
             $valid = false;
         }
     }
     return $valid;
 }
 /**
  * Allows validation of fields via specification of a php function for
  * validation which is executed after the form is submitted.
  *
  * @param array $data
  *
  * @return boolean
  */
 public function php($data)
 {
     $valid = parent::php($data);
     $fields = $this->form->Fields();
     if ($this->unique) {
         foreach ($this->unique as $fieldName => $Message) {
             if (!$fieldName) {
                 continue;
             }
             if ($fieldName instanceof FormField) {
                 $formField = $fieldName;
                 $fieldName = $fieldName->getName();
             } else {
                 $formField = $fields->dataFieldByName($fieldName);
             }
             if ($o = DataObject::get_one($this->objectClass, $fieldName . "='" . Convert::raw2sql($data[$fieldName]) . "'")) {
                 $this->validationError($fieldName, $Message);
                 $valid = false;
             }
         }
     }
     return $valid;
 }
Ejemplo n.º 19
0
 /**
  * Check if the submitted member data is valid (server-side)
  *
  * Check if a member with that email doesn't already exist, or if it does
  * that it is this member.
  *
  * @param array $data Submitted data
  * @return bool Returns TRUE if the submitted data is valid, otherwise
  *              FALSE.
  */
 function php($data)
 {
     $valid = parent::php($data);
     $identifierField = Member::get_unique_identifier_field();
     $SQL_identifierField = Convert::raw2sql($data[$identifierField]);
     $member = DataObject::get_one('Member', "\"{$identifierField}\" = '{$SQL_identifierField}'");
     // if we are in a complex table field popup, use ctf[childID], else use ID
     if (isset($_REQUEST['ctf']['childID'])) {
         $id = $_REQUEST['ctf']['childID'];
     } elseif (isset($_REQUEST['ID'])) {
         $id = $_REQUEST['ID'];
     } else {
         $id = null;
     }
     if ($id && is_object($member) && $member->ID != $id) {
         $uniqueField = $this->form->dataFieldByName($identifierField);
         $this->validationError($uniqueField->id(), sprintf(_t('Member.VALIDATIONMEMBEREXISTS', 'A member already exists with the same %s'), strtolower($identifierField)), 'required');
         $valid = false;
     }
     // Execute the validators on the extensions
     if ($this->extension_instances) {
         foreach ($this->extension_instances as $extension) {
             if (method_exists($extension, 'hasMethod') && $extension->hasMethod('updatePHP')) {
                 $valid &= $extension->updatePHP($data, $this->form);
             }
         }
     }
     return $valid;
 }
 function php($data)
 {
     $this->form->saveDataToSession();
     return parent::php($data);
 }
 /**
  * Ensures member unique id stays unique.
  */
 public function php($data)
 {
     $valid = parent::php($data);
     $field = (string) Member::config()->unique_identifier_field;
     if (isset($data[$field])) {
         $uid = $data[$field];
         $currentMember = Member::currentUser();
         //can't be taken
         if (Member::get()->filter($field, $uid)->exclude('ID', $currentMember->ID)->count() > 0) {
             // get localized field labels
             $fieldLabels = $currentMember->fieldLabels(false);
             // if a localized value exists, use this for our error-message
             $fieldLabel = isset($fieldLabels[$field]) ? $fieldLabels[$field] : $field;
             $this->validationError($field, _t('Checkout.MemberExists', 'A member already exists with the {Field} {Identifier}', '', array('Field' => $fieldLabel, 'Identifier' => $uid)), "required");
             $valid = false;
         }
     }
     return $valid;
 }
 function php($data)
 {
     $this->form->Fields()->dataFieldByName('PollChoices')->setCustomValidationMessage('Please select at least one option.');
     return parent::php($data);
 }
 /**
  * Ensures member unique id stays unique and other basic stuff...
  * @param array $data = array Form Field Data
  * @param Boolean $allowExistingEmail - see comment below
  * @return Boolean
  **/
 function php($data, $allowExistingEmail = false)
 {
     $this->form->saveDataToSession();
     $valid = parent::php($data);
     $uniqueFieldName = Member::get_unique_identifier_field();
     $loggedInMember = Member::currentUser();
     $loggedInMemberID = 0;
     if (isset($data[$uniqueFieldName]) && $data[$uniqueFieldName]) {
         $isShopAdmin = false;
         if ($loggedInMember) {
             $loggedInMemberID = $loggedInMember->ID;
             if ($loggedInMember->IsShopAdmin()) {
                 $isShopAdmin = true;
             }
         }
         if ($isShopAdmin || $allowExistingEmail) {
             //do nothing
         } else {
             $uniqueFieldValue = Convert::raw2sql($data[$uniqueFieldName]);
             //can't be taken
             $otherMembersWithSameEmail = Member::get()->filter(array($uniqueFieldName => $uniqueFieldValue))->exclude(array("ID" => $loggedInMemberID));
             if ($otherMembersWithSameEmail->count()) {
                 //we allow existing email
                 // if we are currently NOT logged in
                 // in case we place an order!
                 if ($allowExistingEmail) {
                     //do nothing
                 } else {
                     $message = _t("Account.ALREADYTAKEN", "{uniqueFieldValue} is already taken by another member. Please log in or use another {uniqueFieldName}.", array("uniqueFieldValue" => $uniqueFieldValue, "uniqueFieldName" => $uniqueFieldName));
                     $this->validationError($uniqueFieldName, $message, "required");
                     $valid = false;
                 }
             }
         }
     }
     // check password fields are the same before saving
     if (isset($data["PasswordCheck1"]) && isset($data["PasswordCheck2"])) {
         if ($data["PasswordCheck1"] != $data["PasswordCheck2"]) {
             $this->validationError("PasswordCheck1", _t('Account.PASSWORDSERROR', 'Passwords do not match.'), "required");
             $valid = false;
         }
         //if you are not logged in, you have not provided a password and the settings require you to be logged in then
         //we have a problem
         if (!$loggedInMember && !$data["PasswordCheck1"] && EcommerceConfig::get("EcommerceRole", "must_have_account_to_purchase")) {
             $this->validationError("PasswordCheck1", _t('Account.SELECTPASSWORD', 'Please select a password.'), "required");
             $valid = false;
         }
         $letterCount = strlen($data["PasswordCheck1"]);
         $minLength = Config::inst()->get("ShopAccountForm_Validator", "minimum_password_length");
         if ($letterCount > 0 && $letterCount < $minLength) {
             $this->validationError("PasswordCheck1", _t('Account.PASSWORDMINIMUMLENGTH', 'Password does not meet minimum standards.'), "required");
             $valid = false;
         }
     }
     if (isset($data["FirstName"])) {
         if (strlen($data["FirstName"]) < 2) {
             $this->validationError("FirstName", _t('Account.NOFIRSTNAME', 'Please enter your first name.'), "required");
             $valid = false;
         }
     }
     if (isset($data["Surname"])) {
         if (strlen($data["Surname"]) < 2) {
             $this->validationError("Surname", _t('Account.NOSURNAME', 'Please enter your surname.'), "required");
             $valid = false;
         }
     }
     if (!$valid) {
         $this->form->sessionMessage(_t('Account.ERRORINFORM', 'We could not save your details, please check your errors below.'), "bad");
     }
     return $valid;
 }
Ejemplo n.º 24
0
 /**
  * Ensures member unique id stays unique and other basic stuff...
  * @param array $data = Form Data
  * @return Boolean
  */
 function php($data)
 {
     $valid = parent::php($data);
     $checkoutPage = DataObject::get_one("CheckoutPage");
     if ($checkoutPage->TermsAndConditionsMessage) {
         if (isset($data["ReadTermsAndConditions"])) {
             if (!$data["ReadTermsAndConditions"]) {
                 $this->validationError("ReadTermsAndConditions", $checkoutPage->TermsAndConditionsMessage, "required");
                 $valid = false;
             }
         }
     }
     $order = ShoppingCart::current_order();
     if (!$order) {
         $this->validationError("Order", _t("OrderForm.ORDERNOTFOUND", "There was an error in processing your order, please try again or contact the administrator."), "required");
         $valid = false;
     }
     $billingAddress = DataObject::get_by_id("BillingAddress", intval($order->BillingAddressID) - 0);
     if (!$billingAddress) {
         $this->validationError("BillingAddress", _t("OrderForm.MUSTHAVEBILLINGADDRESS", "All orders must have a billing address."), "required");
         $valid = false;
     }
     return $valid;
 }
Ejemplo n.º 25
0
 /**
  * Check if the submitted member data is valid (server-side)
  *
  * Check if a member with that email doesn't already exist, or if it does
  * that it is this member.
  *
  * @param array $data Submitted data
  * @return bool Returns TRUE if the submitted data is valid, otherwise
  *              FALSE.
  */
 function php($data)
 {
     $valid = parent::php($data);
     $member = DataObject::get_one('Member', "Email = '" . Convert::raw2sql($data['Email']) . "'");
     // if we are in a complex table field popup, use ctf[childID], else use
     // ID
     if (isset($_REQUEST['ctf']['childID'])) {
         $id = $_REQUEST['ctf']['childID'];
     } elseif (isset($_REQUEST['ID'])) {
         $id = $_REQUEST['ID'];
     } else {
         $id = null;
     }
     if ($id && is_object($member) && $member->ID != $id) {
         $emailField = $this->form->dataFieldByName('Email');
         $this->validationError($emailField->id(), _t('Member.VALIDATIONMEMBEREXISTS', "There already exists a member with this email"), "required");
         $valid = false;
     }
     // Execute the validators on the extensions
     if ($this->extension_instances) {
         foreach ($this->extension_instances as $extension) {
             if ($extension->hasMethod('updatePHP')) {
                 $valid &= $extension->updatePHP($data, $this->form);
             }
         }
     }
     return $valid;
 }
 function php($data)
 {
     $valid = parent::php($data);
     if ($data['VideoType'] == 'Embed') {
         if ($data['VideoAddress'] != '') {
             if (VideoUtility::validate_video($data['VideoAddress']) == false) {
                 $this->validationError("VideoError", _t('Video_Validator.ADDRESS_ERROR', 'Please enter a valid Video URL'));
                 $valid = false;
             }
         } else {
             $this->validationError("VideoError", _t('Video_Validator.ADDRESS_REQUIRED', 'Video URL is required for Embeded videos'));
             $valid = false;
         }
     }
     if ($data['VideoType'] == 'File') {
         $videofile = $data['VideoFile'];
         if ($data['VideoFile'] == '') {
             $this->validationError("VideoError", _t('Video_Validator.VIDEOFILE_REQUIRED', 'Video File is required for File videos'));
             $valid = false;
         }
     }
     return $valid;
 }
 /**
  * Ensures member unique id stays unique and other basic stuff...
  * @param $data = array Form Field Data
  * @return Boolean
  **/
 function php($data)
 {
     $valid = parent::php($data);
     $uniqueFieldNameForMember = Member::get_unique_identifier_field();
     $uniqueFieldNameForForm = $uniqueFieldNameForMember . "Signup";
     $loggedInMember = Member::currentUser();
     if (isset($data[$uniqueFieldNameForForm]) && $loggedInMember && $data[$uniqueFieldNameForForm]) {
         if (!$loggedInMember->IsShopAdmin()) {
             $uniqueFieldValue = Convert::raw2sql($data[$uniqueFieldNameForForm]);
             $anotherMember = DataObject::get_one('Member', "\"{$uniqueFieldNameForMember}\" = '{$uniqueFieldValue}' AND \"Member\".\"ID\" <> " . $loggedInMember->ID);
             //can't be taken
             if ($anotherMember->Password) {
                 $message = sprintf(_t("Account.ALREADYTAKEN", '%1$s is already taken by another member. Please log in or use another %2$s'), $uniqueFieldValue, $uniqueFieldNameForForm);
                 $this->validationError($uniqueFieldNameForForm, $message, "required");
                 $valid = false;
             }
         }
     }
     /*
     		// check password fields are the same before saving
     		if(isset($data["Password"]["_Password"]) && isset($data["Password"]["_ConfirmPassword"])) {
     			if($data["Password"]["_Password"] != $data["Password"]["_ConfirmPassword"]) {
     				$this->validationError(
     					"Password",
     					_t('Account.PASSWORDSERROR', 'Passwords do not match.'),
     					"required"
     				);
     				$valid = false;
     			}
     			if(!$loggedInMember && !$data["Password"]["_Password"]) {
     				$this->validationError(
     					"Password",
     					_t('Account.SELECTPASSWORD', 'Please select a password.'),
     					"required"
     				);
     				$valid = false;
     			}
     		}
     		* */
     if (!$valid) {
         $this->form->sessionMessage(_t('Account.ERRORINFORM', 'We could not save your details, please check your errors below.'), "bad");
     }
     return $valid;
 }
Ejemplo n.º 28
0
 /**
  * Check if the submitted member data is valid (server-side)
  *
  * Check if a member with that email doesn't already exist, or if it does
  * that it is this member.
  *
  * @param array $data Submitted data
  * @return bool Returns TRUE if the submitted data is valid, otherwise
  *              FALSE.
  */
 public function php($data)
 {
     $valid = parent::php($data);
     $identifierField = (string) Member::config()->unique_identifier_field;
     // Only validate identifier field if it's actually set. This could be the case if
     // somebody removes `Email` from the list of required fields.
     if (isset($data[$identifierField])) {
         $id = isset($data['ID']) ? (int) $data['ID'] : 0;
         if (!$id && ($ctrl = $this->form->getController())) {
             // get the record when within GridField (Member editing page in CMS)
             if ($ctrl instanceof GridFieldDetailForm_ItemRequest && ($record = $ctrl->getRecord())) {
                 $id = $record->ID;
             }
         }
         // If there's no ID passed via controller or form-data, use the assigned member (if available)
         if (!$id && ($member = $this->getForMember())) {
             $id = $member->exists() ? $member->ID : 0;
         }
         // set the found ID to the data array, so that extensions can also use it
         $data['ID'] = $id;
         $members = Member::get()->filter($identifierField, $data[$identifierField]);
         if ($id) {
             $members = $members->exclude('ID', $id);
         }
         if ($members->count() > 0) {
             $this->validationError($identifierField, _t('Member.VALIDATIONMEMBEREXISTS', 'A member already exists with the same {identifier}', array('identifier' => Member::singleton()->fieldLabel($identifierField))), 'required');
             $valid = false;
         }
     }
     // Execute the validators on the extensions
     $results = $this->extend('updatePHP', $data, $this->form);
     $results[] = $valid;
     return min($results);
 }
 /**
  * Allows validation of fields via specification of a php function for validation which is executed after
  * the form is submitted
  */
 function php($data)
 {
     $valid = true;
     if (!isset($data["Subject"]) || (isset($data["Subject"]) && strlen($data["Subject"])) < 3) {
         $errorMessage = _t("Form.PLEASEENTERASUBJECT", "Please enter a subject");
         $this->validationError($fieldName = "Subject", $errorMessage, "required");
         $valid = false;
     }
     if (!isset($data["To"]) || isset($data["To"]) && strlen($data["To"]) < 3) {
         $errorMessage = _t("Form.PLEASEENTERANEMAIL", "Please enter an e=mail");
         $this->validationError($fieldName = "To", $errorMessage, "required");
     }
     if (!$valid) {
         return false;
     }
     return parent::php($data);
 }
 /**
  * Ensures member unique id stays unique.
  */
 public function php($data)
 {
     $valid = parent::php($data);
     $field = (string) Member::config()->unique_identifier_field;
     if (isset($data[$field])) {
         $uid = $data[(string) Member::config()->unique_identifier_field];
         $currentmember = Member::currentUser();
         //can't be taken
         if (DataObject::get_one('Member', "{$field} = '{$uid}' AND ID != " . $currentmember->ID)) {
             // get localized field labels
             $fieldLabels = $currentmember->fieldLabels(false);
             // if a localized value exists, use this for our error-message
             $fieldLabel = isset($fieldLabels[$field]) ? $fieldLabels[$field] : $field;
             $this->validationError($field, sprintf(_t("Checkout.MEMBEREXISTS", "A member already exists with the %s %s"), $fieldLabel, $uid), "required");
             $valid = false;
         }
     }
     return $valid;
 }