/** * Initializes the form element. */ function init() { // set label $this->setLabel('Email'); // set required $this->setRequired(true); // set filter $this->addFilter('StringTrim'); // add validator for max string length $this->addValidator('StringLength', false, array(0, 256)); // add validator for email addresses $emailValidator = new Zend_Validate_EmailAddress(Zend_Validate_Hostname::ALLOW_DNS | Zend_Validate_Hostname::ALLOW_LOCAL); $this->addValidator($emailValidator); // add validator for beeing unique in the database $validator = new Zend_Validate(); $message = 'The email is already in the database, please check if you are already registered.'; $userTableValidator = new Zend_Validate_Db_NoRecordExists('Auth_User', 'email'); $userTableValidator->setMessage($message); if (!empty($this->_excludeId)) { $userTableValidator->setExclude(array('field' => 'id', 'value' => $this->_excludeId)); } $registrationTableValidator = new Zend_Validate_Db_NoRecordExists('Auth_Registration', 'email'); $registrationTableValidator->setMessage($message); // chainvalidators and add to field $validator->addValidator($userTableValidator)->addValidator($registrationTableValidator); $this->addValidator($validator); }
/** * Initializes the form element. */ function init() { // set filter $this->addFilter('StringTrim'); // set required $this->setRequired(true); // set label $this->setLabel(ucfirst($this->getName())); // set validator for lowercase or regular alnum if (Daiquiri_Config::getInstance()->auth->lowerCaseUsernames) { $this->addValidator(new Daiquiri_Form_Validator_LowerCaseAlnum()); } else { $this->addValidator(new Daiquiri_Form_Validator_AlnumUnderscore()); } // add validator for min and max string length $minLength = Daiquiri_Config::getInstance()->auth->usernameMinLength; $this->addValidator('StringLength', false, array($minLength, 256)); // add validator for beeing unique in the database $validator = new Zend_Validate(); $message = 'The username is in use, please use another username.'; $userTableValidator = new Zend_Validate_Db_NoRecordExists('Auth_User', 'username'); $userTableValidator->setMessage($message); if (!empty($this->_excludeId)) { $userTableValidator->setExclude(array('field' => 'id', 'value' => $this->_excludeId)); } $registrationTableValidator = new Zend_Validate_Db_NoRecordExists('Auth_Registration', 'username'); $registrationTableValidator->setMessage($message); $appTableValidator = new Zend_Validate_Db_NoRecordExists('Auth_Apps', 'appname'); $appTableValidator->setMessage($message); $validator->addValidator($userTableValidator)->addValidator($registrationTableValidator)->addValidator($appTableValidator); $this->addValidator($validator); }
public function __construct($options = null) { parent::__construct($options); $this->setName('product'); $product_name = new Zend_Form_Element_Text('product_name'); $product_name->setLabel('Product Name: ')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty'); $id = new Zend_Form_Element_Hidden('id'); $ProductIdExists = new Zend_Validate_Db_NoRecordExists(array('table' => 'products', 'field' => 'product_id')); $ProductIdExists->setMessage('This Product ID is already taken'); $product_id = new Zend_Form_Element_Text('product_id'); $product_id->setLabel('Product ID: ')->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator($ProductIdExists)->addValidator('NotEmpty'); $category = new Category(); $categoriesList = $category->getCategoriesList(); $category_id = new Zend_Form_Element_Select('category_id'); $category_id->setLabel('Category: ')->addMultiOptions($categoriesList)->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty'); $product_desc = new Zend_Form_Element_Text('product_desc'); $product_desc->setLabel('Description ')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty'); $product_img = new Zend_Form_Element_File('product_image'); $product_img->setLabel('Upload an image:')->setDestination(PUBLIC_PATH . '/images'); // ensure only 1 file $product_img->addValidator('Count', false, 1); // limit to 100K $product_img->addValidator('Size', false, 102400); // only JPEG, PNG, and GIFs $product_img->addValidator('Extension', false, 'jpg,png,gif'); $submit = new Zend_Form_Element_Submit('submit'); $submit->setAttrib('id', 'submitbutton'); $this->setAttrib('enctype', 'multipart/form-data'); $this->addElements(array($product_name, $product_id, $product_desc, $product_img, $id, $category_id, $submit)); }
public function init() { $this->setAttrib('class', 'form-horizontal'); $login = new Zend_Form_Element_Text('login'); $login->setRequired()->addValidator('StringLength', false, array('max' => 32))->setLabel('Nom d\'utilisateur'); $db = Zend_Db_Table::getDefaultAdapter(); $validator = new Zend_Validate_Db_NoRecordExists(array('adapter' => $db, 'schema' => 'twitter', 'table' => 'membre', 'field' => 'login')); $validator->setMessage("Le login '%value%' est déjà utilisé"); $login->addValidator($validator); $pass = new Zend_Form_Element_Password('pass'); $pass->setLabel('Mot de passe')->setRequired(); $passConfirm = new Zend_Form_Element_Password('confirm'); $passConfirm->setLabel('Confirmer le mot de passe'); $validator = new Zend_Validate_Identical('pass'); $validator->setMessage('La confirmation ne correspond pas au mot de passe'); $passConfirm->addValidator($validator); //$passConfirm->addValidator('Identical', false, array('token')); $hash = new Zend_Form_Element_Hash('hash'); $submit = new Zend_Form_Element_Submit('Inscription'); $cancel = new Zend_Form_Element_Button('Annuler'); $this->addElements(array($login, $pass, $passConfirm, $hash, $submit, $cancel)); // add display group $this->addDisplayGroup(array('login', 'pass', 'confirm', 'Inscription', 'Annuler'), 'users'); $this->getDisplayGroup('users')->setLegend('S\'inscrire'); // set decorators EasyBib_Form_Decorator::setFormDecorator($this, EasyBib_Form_Decorator::BOOTSTRAP, 'Inscription', 'Annuler'); }
public function addNewPropertyAction() { $request = $this->getRequest(); $dataResponse = array(); if ($request->isPost()) { $pipelineId = $request->getParam('pipelineId'); $propertyName = $request->getParam('newPropertyName'); $propertyValue = $request->getParam('newPropertyValue'); $validator = new Zend_Validate_Db_NoRecordExists(array('table' => 'pipeline_property', 'field' => 'sistem_name')); $systemName = $this->_getSistemNameProperty($propertyName); if ($systemName != '' && $validator->isValid(strtolower($systemName))) { $newProperty = $this->_createNewProperty($propertyName); if (!is_null($newProperty) && $request->getParam('pipelineId') != 0) { $newPropertyValue = $this->_createPropertyValue($pipelineId, $newProperty->getId(), $propertyValue); if (!is_null($newPropertyValue)) { $dataResponse['property'] = array('propertyValueId' => $newPropertyValue->getId(), 'propertyName' => $newProperty->getName(), 'propertyValue' => $newPropertyValue->getValue()); } } } else { $alert = '<div class="alert alert-danger" role="alert"> <h4 class="text-center">Cвойство <a href="/admin/pipeline-property/">"' . $request->getParam('newPropertyName') . '"</a> уже существует.</h4> </div>'; $dataResponse['errorMessage'] = $alert; } } echo $this->_helper->json($dataResponse); }
public function addDBNoRecordExistsValidator() { $email = $this->getElement('email'); $validator = new Zend_Validate_Db_NoRecordExists(array('table' => 'accounts', 'field' => 'email')); $validator->setMessage("This email already exists in our database"); $email->addValidator($validator); }
/** * Validates email address * * @return boolean */ protected function _validateEmail() { $validator = new Zend_Validate_EmailAddress(); $msg = Sanmax_MessageStack::getInstance('SxCms_User'); if (!$validator->isValid($this->_user->getEmail())) { $msg->addMessage('email', $validator->getMessages()); } $exclude = array('field' => 'user_id', 'value' => (int) $this->_user->getId()); $validator = new Zend_Validate_Db_NoRecordExists('User', 'email', $exclude); if (!$validator->isValid($this->_user->getEmail())) { $msg->addMessage('email', $validator->getMessages(), 'common'); } return false == $msg->getMessages('email'); }
public function checkEmail($email) { $validator = new Zend_Validate_EmailAddress(); if ($validator->isValid($email)) { // email address appears to be valid $validatorEmail = new Zend_Validate_Db_NoRecordExists(array('table' => 'usuario_login', 'field' => 'email')); if ($validatorEmail->isValid($email)) { return true; } else { return false; } } else { return false; } }
public function redirectsAction() { $redirectForm = new Application_Form_Redirect(); $pageMapper = Application_Model_Mappers_PageMapper::getInstance(); $redirectMapper = Application_Model_Mappers_RedirectMapper::getInstance(); $redirectForm->setToasterPages($pageMapper->fetchIdUrlPairs()); $redirectForm->setDefault('fromUrl', 'http://'); if (!$this->getRequest()->isPost()) { $this->view->redirects = $redirectMapper->fetchRedirectMap(); } else { if ($redirectForm->isValid($this->getRequest()->getParams())) { $data = $redirectForm->getValues(); $redirect = new Application_Model_Models_Redirect(); $fromUrlPath = Tools_System_Tools::getUrlPath($data['fromUrl']); $inDbValidator = new Zend_Validate_Db_NoRecordExists(array('table' => 'redirect', 'field' => 'from_url')); if (!$inDbValidator->isValid($fromUrlPath)) { $this->_helper->response->fail(implode('<br />', $inDbValidator->getMessages())); exit; } $redirect->setFromUrl(Tools_System_Tools::getUrlPath($data['fromUrl'])); $redirect->setDomainFrom(Tools_System_Tools::getUrlScheme($data['fromUrl']) . '://' . Tools_System_Tools::getUrlHost($data['fromUrl']) . '/'); if (intval($data['toUrl'])) { $page = $pageMapper->find($data['toUrl']); $redirect->setDomainTo($this->_helper->website->getUrl()); $redirect->setToUrl($page->getUrl()); $redirect->setPageId($page->getId()); } else { $urlValidator = new Validators_UrlRegex(); if (!$urlValidator->isValid($data['toUrl'])) { $this->_helper->response->fail('External url <br />' . implode('<br />', $urlValidator->getMessages())); exit; } $redirect->setDomainTo(Tools_System_Tools::getUrlScheme($data['toUrl']) . '://' . Tools_System_Tools::getUrlHost($data['toUrl']) . '/'); $redirect->setToUrl(Tools_System_Tools::getUrlPath($data['toUrl'])); $redirect->setPageId(null); } $redirectMapper->save($redirect); $this->_helper->cache->clean('toaster_301redirects', '301redirects'); $this->_helper->response->success('Redirect saved'); } else { $this->_helper->response->fail(Tools_Content_Tools::proccessFormMessagesIntoHtml($redirectForm->getMessages(), get_class($redirectForm))); exit; } } $this->view->helpSection = '301s'; $this->view->form = $redirectForm; }
public function isValid($value) { $valid = parent::isValid($value); if ($valid === false) { $this->_error(self::USERNAME_NOT_UNIQUE); } return $valid; }
public function newAction() { $request = $this->getRequest(); if ($request->isPost()) { $validator = new Zend_Validate_Db_NoRecordExists(array('table' => 'pipeline_property', 'field' => 'sistem_name')); if ($validator->isValid(strtolower($request->getParam('newPropertySystemName')))) { $newProperty = $this->_createNewProperty(); if (!is_null($newProperty) && $request->getParam('pipelineId') != 0) { $newPropertyValue = $this->_createNewPropertyValue($newProperty->getId()); echo $this->_helper->json($this->_createDataHtml($newProperty, $newPropertyValue)); } } else { // username is invalid; print the reason $messages = $validator->getMessages(); foreach ($messages as $message) { $message = '<tr><td colspan="3"><div class="alert alert-danger" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>' . $message . '</div></td></tr>'; echo $this->_helper->json($message); } } } }
/** * Constructs the validator * * @param Zend_Config|array $config * @access public * @return void */ public function __construct($config) { parent::__construct($config); if ($config instanceof Zend_Config) { $config = $config->toArray(); } if (isset($config['treatment'])) { $this->setTreatment($config['treatment']); } if (isset($config['userPkField'])) { $this->setUserPkField($config['userPkField']); } if (isset($config['userPkValue'])) { $this->setUserPkValue($config['userPkValue']); } }
public function przypomnijhasloAction() { // action body if ($this->_request->isXmlHttpRequest()) { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $post = $this->_request->getPost(); $return = array('email' => true); $ile_poprawnych = count($return); $zwroconych = 0; // email $empty = new Zend_Validate_NotEmpty(); $isvalidEmail = new Zend_Validate_EmailAddress(Zend_Validate_Hostname::ALLOW_DNS | Zend_Validate_Hostname::ALLOW_LOCAL); $emailIsNotExist = new Zend_Validate_Db_NoRecordExists(array('table' => 'ts_wydania_prenumerata_users_pl', 'field' => 'email', 'exclude' => '(czy_aktywne<>"Y") AND (email="' . $post['email'] . '")')); //$return['email'] = !$emailIsExist->isValid($post['email']); if (!$empty->isValid($post['email'])) { $return['email'] = 'null'; } elseif (!$isvalidEmail->isValid($post['email'])) { $return['email'] = 'wrong'; } elseif ($emailIsNotExist->isValid($post['email'])) { $return['email'] = 'unexist'; } else { $zwroconych++; } /**/ // finalizowanie if ($ile_poprawnych == $zwroconych) { try { $salt = TS_Salt::getSalt3(); $User = new Application_Model_DbTable_UzytkownicyWww(); //$post["email"] = $User->getAdapter()->quote($post["email"]); $dane = array('salt' => $salt); $User->update($dane, array('email = ?' => $post["email"])); //$request = Zend_Controller_Front::getInstance()->getRequest(); //$baseUrl = $request->getScheme() . '://' . $request->getHttpHost(); $baseUrl = $this->view->serverUrl() . $this->view->baseUrl(); $mail = new TS_Mail(); $mail_dane = array('to' => $post['email'], 'subject' => 'Zmiana hasła', 'view' => array('script' => 'zmianahasla', 'params' => array('salt' => $baseUrl . '/user-przypomnijhaslopotwierdz.htm?salt=' . $salt))); $mail->send($mail_dane); } catch (Exception $ex) { die($ex->getMessage()); } } /**/ echo json_encode($return); } else { $this->view->podajmaila = new Application_Form_PodajMaila(); } }
/** * Check uniqueness of one of the record's fields. * * @uses Zend_Validate_Db_NoRecordExists * @param string $field * @param mixed $value Optional If null, this will check the value of the * record's $field. Otherwise check the uniqueness of this value for the * given field. * @return boolean */ protected function fieldIsUnique($field, $value = null) { $value = $value ? $value : $this->{$field}; if ($value === null) { throw new Omeka_Record_Exception("Cannot check uniqueness of NULL value."); } $validatorOptions = array('table' => $this->getTable()->getTableName(), 'field' => $field, 'adapter' => $this->getDb()->getAdapter()); // If this record already exists, exclude it from the validation if ($this->exists()) { $validatorOptions['exclude'] = array('field' => 'id', 'value' => $this->id); } $validator = new Zend_Validate_Db_NoRecordExists($validatorOptions); return $validator->isValid($value); }
public function __construct($options = null) { $this->_addSubmitSaveClose = true; parent::__construct($options); $this->setName('page'); //$imageSrc = $options['imageSrc']; $pageID = $options['pageID']; $imageHeaderArray = $options['imageHeaderArray']; // contains the id of the page $id = new Zend_Form_Element_Hidden('id'); $id->removeDecorator('Label'); $id->removeDecorator('HtmlTag'); // input text for the title of the page $title = new Zend_Form_Element_Text('PI_PageTitle'); $title->setLabel($this->getView()->getCibleText('label_titre_page'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => Cible_Translation::getCibleText('error_field_required')))->setAttrib('class', 'stdTextInput')->setAttrib('onBlur', 'javascript:fillInControllerName();'); $lblTit = $title->getDecorator('Label'); $lblTit->setOption('class', $this->_labelCSS); // input text for the index of the page $uniqueIndexValidator = new Zend_Validate_Db_NoRecordExists('PagesIndex', 'PI_PageIndex'); $uniqueIndexValidator->setMessage($this->getView()->getCibleText('label_index_already_exists'), Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND); $reservedWordValidator = new Cible_Validate_Db_NoRecordExists('Modules', 'M_MVCModuleTitle'); $reservedWordValidator->setMessage($this->getView()->getCibleText('label_index_reserved'), Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND); $index = new Zend_Form_Element_Text('PI_PageIndex'); $index->setLabel($this->getView()->getCibleText('label_name_controller'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addFilter('StringToLower')->addValidator('NotEmpty', true, array('messages' => Cible_Translation::getCibleText('error_field_required')))->addValidator('stringLength', true, array(1, 50, 'messages' => array(Zend_Validate_StringLength::TOO_SHORT => $this->getView()->getCibleText('label_index_more_char'), Zend_Validate_StringLength::TOO_LONG => $this->getView()->getCibleText('label_index_less_char'))))->addValidator('regex', true, array('/^[a-z0-9][a-z0-9_-]*[a-z0-9]$/', 'messages' => $this->getView()->getCibleText('label_only_character_allowed')))->addValidator($uniqueIndexValidator, true)->addValidator($reservedWordValidator, true)->setAttrib('class', 'stdTextInput'); $lblId = $index->getDecorator('Label'); $lblId->setOption('class', $this->_labelCSS); // textarea for the meta and title of the page $metaTitle = new Zend_Form_Element_Textarea('PI_MetaTitle'); $metaTitle->setLabel('Titre (meta)')->setRequired(false)->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('class', 'stdTextareaShort'); $lblMetaTitle = $metaTitle->getDecorator('Label'); $lblMetaTitle->setOption('class', $this->_labelCSS); // textarea for the meta description of the page $metaDescription = new Zend_Form_Element_Textarea('PI_MetaDescription'); $metaDescription->setLabel($this->getView()->getCibleText('label_description_meta'))->setRequired(false)->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('class', 'stdTextareaShort'); $lblMetaDescr = $metaDescription->getDecorator('Label'); $lblMetaDescr->setOption('class', $this->_labelCSS); // textarea for the meta keywords of the page $metaKeyWords = new Zend_Form_Element_Textarea('PI_MetaKeywords'); $metaKeyWords->setLabel($this->getView()->getCibleText('label_keywords_meta'))->setRequired(false)->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('class', 'stdTextareaShort'); $lblMetaKey = $metaKeyWords->getDecorator('Label'); $lblMetaKey->setOption('class', $this->_labelCSS); // textarea for the meta keywords of the page $metaOthers = new Zend_Form_Element_Textarea('PI_MetaOther'); $metaOthers->setLabel($this->getView()->getCibleText('label_other_meta'))->setRequired(false)->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('class', 'stdTextareaShort'); $lblMetaOther = $metaOthers->getDecorator('Label'); $lblMetaOther->setOption('class', $this->_labelCSS); // select box for the templates $layout = new Zend_Form_Element_Select('P_LayoutID'); $layout->setLabel($this->getView()->getCibleText('label_layout_page'))->setAttrib('class', 'stdSelect'); // select box for the templates $template = new Zend_Form_Element_Select('P_ViewID'); $template->setLabel($this->getView()->getCibleText('label_model_page'))->setAttrib('class', 'stdSelect'); // checkbox for the status (0 = offline, 1 = online) $status = new Zend_Form_Element_Checkbox('PI_Status'); $status->setValue(1); $status->setLabel($this->getView()->getCibleText('form_check_label_online')); $status->setDecorators(array('ViewHelper', array('label', array('placement' => 'append')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'label_after_checkbox')))); // checkbox for the show title of the page (0 = offline, 1 = online) $showTitle = new Zend_Form_Element_Checkbox('P_ShowTitle'); $showTitle->setValue(1); $showTitle->setLabel($this->getView()->getCibleText('form_check_label_show_title')); $showTitle->setDecorators(array('ViewHelper', array('label', array('placement' => 'append')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'label_after_checkbox')))); // image group // ImageSrc /*$imageSrc = new Zend_Form_Element_Select('P_BannerGroupID'); $imageSrc->setLabel($this->getView()->getCibleText('form_banner_image_group_extranet'))->setAttrib('class','stdSelect'); $imageSrc->addMultiOption('', 'Sans image'); $group = new GroupObject(); $groupArray = $group->groupCollection(); foreach ($groupArray as $group1) { $imageSrc->addMultiOption($group1['BG_ID'],$group1['BG_Name']); }*/ // page image $imageSrc = new Zend_Form_Element_Select('PI_TitleImageSrc'); $imageSrc->setLabel("Image de l'entête")->setAttrib('class', 'stdSelect'); $imageSrc->addMultiOption('', 'Sans image'); $i = 1; foreach ($imageHeaderArray as $img => $path) { $imageSrc->addMultiOption($path, $path); $i++; } $altImage = new Zend_Form_Element_Text('PI_AltPremiereImage'); $altImage->setLabel($this->getView()->getCibleText('label_altFirstImage'))->setAttrib('class', 'stdTextInput'); // add element to the form $this->addElements(array($title, $index, $status, $showTitle, $layout, $template, $imageSrc, $altImage, $metaTitle, $metaDescription, $metaKeyWords, $metaOthers, $id)); }
public function __construct($options = null) { $this->_disabledDefaultActions = true; parent::__construct($options); $baseDir = $this->getView()->baseUrl(); if (!empty($options['mode']) && $options['mode'] == 'edit') { $this->_mode = 'edit'; } else { $this->_mode = 'add'; } $langId = Zend_Registry::get('languageID'); $this->setAttrib('id', 'accountManagement'); // $addressParams = array( // "fieldsValue" => array(), // "display" => array(), // "required" => array(), // ); // Salutation $salutation = new Zend_Form_Element_Select('salutation'); $salutation->setLabel($this->getView()->getCibleText('form_label_salutation'))->setAttrib('class', 'smallSelect')->setAttrib('tabindex', '1')->setOrder(1); $greetings = $this->getView()->getAllSalutation(); foreach ($greetings as $greeting) { $salutation->addMultiOption($greeting['S_ID'], $greeting['ST_Value']); } // Language $languages = new Zend_Form_Element_Select('language'); $languages->setLabel($this->getView()->getCibleText('form_label_language'))->setAttrib('class', 'stdSelect')->setAttrib('tabindex', '9')->setOrder(9); foreach (Cible_FunctionsGeneral::getAllLanguage() as $lang) { $languages->addMultiOption($lang['L_ID'], $lang['L_Title']); } // FirstName $firstname = new Zend_Form_Element_Text('firstName'); $firstname->setLabel($this->getView()->getCibleText('form_label_fName'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))->setAttribs(array('class' => 'stdTextInput'))->setAttrib('tabindex', '2')->setOrder(2); // LastName $lastname = new Zend_Form_Element_Text('lastName'); $lastname->setLabel($this->getView()->getCibleText('form_label_lName'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))->setAttribs(array('class' => 'stdTextInput'))->setAttrib('tabindex', '3')->setOrder(3); // email $regexValidate = new Cible_Validate_Email(); $regexValidate->setMessage($this->getView()->getCibleText('validation_message_emailAddressInvalid'), 'regexNotMatch'); $emailNotFoundInDBValidator = new Zend_Validate_Db_NoRecordExists('GenericProfiles', 'GP_Email'); $emailNotFoundInDBValidator->setMessage($this->getView()->getClientText('validation_message_email_already_exists'), 'recordFound'); $email = new Zend_Form_Element_Text('email'); $email->setLabel($this->getView()->getCibleText('form_label_email'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addFilter('StringToLower')->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))->addValidator($regexValidate)->setAttribs(array('maxlength' => 50, 'class' => 'stdTextInput'))->setAttrib('tabindex', '5')->setOrder(5); if ($this->_mode == 'add') { $email->addValidator($emailNotFoundInDBValidator); } // email // password $password = new Zend_Form_Element_Password('password'); if ($this->_mode == 'add') { $password->setLabel($this->getView()->getCibleText('form_label_password')); } else { $password->setLabel($this->getView()->getCibleText('form_label_newPwd')); } $password->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('class', 'stdTextInput')->setAttrib('tabindex', '6')->setRequired(true)->setOrder(6)->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field')))); // password // password confirmation $passwordConfirmation = new Zend_Form_Element_Password('passwordConfirmation'); if ($this->_mode == 'add') { $passwordConfirmation->setLabel($this->getView()->getCibleText('form_label_confirmPwd')); } else { $passwordConfirmation->setLabel($this->getView()->getCibleText('form_label_confirmPwd')); } // $passwordConfirmation->setLabel($this->getView()->getCibleText('form_label_confirmNewPwd')); $passwordConfirmation->addFilter('StripTags')->addFilter('StringTrim')->setRequired(true)->setOrder(7)->setAttrib('class', 'stdTextInput')->setAttrib('tabindex', '7')->setDecorators(array('ViewHelper', array(array('row' => 'HtmlTag'), array('tag' => 'dd')), array('label', array('class' => 'test', 'tag' => 'dt', 'tagClass' => 'alignVertical')))); if (!empty($_POST['identification']['password'])) { $passwordConfirmation->setRequired(true)->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('error_message_password_isEmpty')))); $Identical = new Zend_Validate_Identical($_POST['identification']['password']); $Identical->setMessages(array('notSame' => $this->getView()->getCibleText('error_message_password_notSame'))); $passwordConfirmation->addValidator($Identical); } // password confirmation // Company name $company = new Zend_Form_Element_Text('company'); $company->setLabel($this->getView()->getCibleText('form_label_company'))->setRequired(false)->setAttrib('tabindex', '4')->setOrder(4)->setAttribs(array('class' => 'stdTextInput')); // Account number $account = new Zend_Form_Element_Text('accountNum'); $account->setLabel($this->getView()->getCibleText('form_label_account'))->setRequired(true)->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))->setOrder(8)->setAttribs(array('class' => 'stdTextInput'))->setAttrib('tabindex', '8')->setDecorators(array('ViewHelper', 'Errors', array(array('row' => 'HtmlTag'), array('tag' => 'dd')), array('label', array('class' => 'test', 'tag' => 'dt', 'tagClass' => 'alignVertical')))); // Text Subscribe $textSubscribe = $this->getView()->getCibleText('form_label_subscribe'); $textSubscribe = str_replace('%URL_PRIVACY_POLICY%', Cible_FunctionsPages::getPageLinkByID($this->_config->privacyPolicy->pageId), $textSubscribe); // Newsletter subscription $newsletterSubscription = new Zend_Form_Element_Checkbox('newsletterSubscription'); $newsletterSubscription->setLabel($textSubscribe); if ($this->_mode == 'add') { $newsletterSubscription->setChecked(1); } $newsletterSubscription->setAttrib('class', 'long-text'); $newsletterSubscription->setDecorators(array('ViewHelper', array('label', array('placement' => 'append')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'id' => 'subscribeNewsletter', 'class' => 'label_after_checkbox')))); if ($this->_mode == 'add') { $termsAgreement = new Zend_Form_Element_Checkbox('termsAgreement'); $termsAgreement->setLabel(str_replace('%URL_TERMS_CONDITIONS%', Cible_FunctionsPages::getPageLinkByID($this->_config->termsAndConditions->pageId), $this->getView()->getClientText('form_label_terms_agreement'))); $termsAgreement->setAttrib('class', 'long-text'); $termsAgreement->setDecorators(array('ViewHelper', array('label', array('placement' => 'append')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'label_after_checkbox')))); $termsAgreement->setRequired(true); $termsAgreement->addValidator('notEmpty', true, array('messages' => array('isEmpty' => 'You must agree to the terms'))); } else { $termsAgreement = new Zend_Form_Element_Hidden('termsAgreement', array('value' => 1)); } // Submit button $submit = new Zend_Form_Element_Submit('submit'); $submitLabel = $this->getView()->getCibleText('form_account_button_submit'); if ($this->_mode == 'edit') { $submitLabel = $this->getView()->getCibleText('button_submit'); } $submit->setLabel($submitLabel)->setAttrib('class', 'stdButton subscribeButton1-' . Zend_Registry::get("languageSuffix")); // Captcha // Refresh button $refresh_captcha = new Zend_Form_Element_Button('refresh_captcha'); $refresh_captcha->setLabel($this->getView()->getCibleText('button_refresh_captcha'))->setAttrib('onclick', "refreshCaptcha('captcha-id')")->setAttrib('class', 'stdButton')->removeDecorator('Label')->removeDecorator('DtDdWrapper'); $refresh_captcha->addDecorators(array(array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'dd-refresh-captcha-button')))); $captcha = new Zend_Form_Element_Captcha('captcha', array('label' => $this->getView()->getCibleText('form_label_securityCaptcha'), 'captcha' => 'Image', 'captchaOptions' => array('captcha' => 'Word', 'wordLen' => 5, 'fontSize' => 28, 'height' => 67, 'width' => 169, 'timeout' => 300, 'dotNoiseLevel' => 0, 'lineNoiseLevel' => 0, 'font' => Zend_Registry::get('application_path') . "/../{$this->_config->document_root}/captcha/fonts/ARIAL.TTF", 'imgDir' => Zend_Registry::get('application_path') . "/../{$this->_config->document_root}/captcha/tmp", 'imgUrl' => "{$baseDir}/captcha/tmp"))); $captcha->setAttrib('class', 'stdTextInputCatcha'); $captcha->setRequired(true); $captcha->addDecorators(array(array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'id' => 'dd_captcha'))))->addDecorator('Label', array('class' => 'clear')); $french = array('badCaptcha' => 'Veuillez saisir la chaîne ci-dessus correctement.'); $english = array('badCaptcha' => 'Captcha value is wrong'); $translate = new Zend_Translate('array', $french, 'fr'); $this->setTranslator($translate); $this->getView()->jQuery()->enable(); $script = <<<EOS function refreshCaptcha(id){ \$.getJSON('{$this->getView()->baseUrl()}/newsletter/index/captcha-reload', function(data){ \$("dd#dd_captcha img").attr({src : data['url']}); \$("#"+id).attr({value: data['id']}); }); } EOS; $this->getView()->headScript()->appendScript($script); // Captcha /* Identification sub form */ $identificationSub = new Cible_Form_SubForm(); $identificationSub->setName('identification')->removeDecorator('DtDdWrapper'); $identificationSub->setLegend($this->getView()->getCibleText('form_account_subform_identification_legend')); $identificationSub->setAttrib('class', 'identificationClass subFormClass'); $identificationSub->addElement($languages); $identificationSub->addElement($salutation); $identificationSub->addElement($lastname); $identificationSub->addElement($firstname); $identificationSub->addElement($email); $identificationSub->addElement($password); $identificationSub->addElement($passwordConfirmation); $identificationSub->addElement($company); $identificationSub->addElement($account); $identificationSub->addDisplayGroup(array('salutation', 'firstName', 'company', 'password', 'accountNum'), 'leftColumn'); $identificationSub->addDisplayGroup(array('lastName', 'email', 'passwordConfirmation', 'language'), 'rightColumn')->removeDecorator('DtDdWrapper'); $leftColGroup = $identificationSub->getDisplayGroup('leftColumn'); $rightColGroup = $identificationSub->getDisplayGroup('rightColumn'); $leftColGroup->removeDecorator('DtDdWrapper'); $rightColGroup->removeDecorator('DtDdWrapper'); $this->addSubForm($identificationSub, 'identification'); // Billing address $addressFacturationSub = new Cible_Form_SubForm(); $addressFacturationSub->setName('addressFact')->removeDecorator('DtDdWrapper'); $addressFacturationSub->setLegend($this->getView()->getCibleText('form_account_subform_addBilling_legend')); $addressFacturationSub->setAttrib('class', 'addresseBillingClass subFormClass'); $billingAddr = new Cible_View_Helper_FormAddress($addressFacturationSub); $billingAddr->enableFields(array('firstAddress', 'secondAddress', 'cityTxt', 'zipCode', 'country', 'state', 'firstTel', 'secondTel', 'fax')); $billingAddr->formAddress(); $addrBill = new Zend_Form_Element_Hidden('addrBill'); $addrBill->removeDecorator('label'); $addressFacturationSub->addElement($addrBill); $this->addSubForm($addressFacturationSub, 'addressFact'); /* delivery address */ $addrShip = new Zend_Form_Element_Hidden('addrShip'); $addrShip->removeDecorator('label'); $addressShippingSub = new Cible_Form_SubForm(); $addressShippingSub->setName('addressShipping')->removeDecorator('DtDdWrapper'); $addressShippingSub->setLegend($this->getView()->getCibleText('form_account_subform_addShipping_legend')); $addressShippingSub->setAttrib('class', 'addresseShippingClass subFormClass'); $shipAddr = new Cible_View_Helper_FormAddress($addressShippingSub); $shipAddr->duplicateAddress($addressShippingSub); $shipAddr->setProperty('addScriptState', false); $shipAddr->enableFields(array('firstAddress', 'secondAddress', 'cityTxt', 'zipCode', 'country', 'state', 'firstTel', 'secondTel', 'fax')); $shipAddr->formAddress(); $addressShippingSub->addElement($addrShip); $this->addSubForm($addressShippingSub, 'addressShipping'); if ($this->_mode == 'add') { $this->getView()->jQuery()->enable(); $script = <<<EOS function refreshCaptcha(id){ \$.getJSON('{$this->getView()->baseUrl()}/order/index/captcha-reload', function(data){ \$("dd#dd_captcha img").attr({src : data['url']}); \$("#"+id).attr({value: data['id']}); }); } EOS; // $this->getView()->headScript()->appendScript($script); // $this->addElement($refresh_captcha); // $this->addElement($captcha); $this->addElement($newsletterSubscription); $this->addElement($termsAgreement); } $this->addElement($submit); $submit->setDecorators(array('ViewHelper', array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'account-submit')))); if ($this->_mode == 'add') { $termsAgreement->setDecorators(array('ViewHelper', array('label', array('placement' => 'append')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'label_after_checkbox', 'id' => 'dd-terms-agreement')))); } $captchaError = array('badCaptcha' => $this->getView()->getCibleText('validation_message_captcha_error')); $translate = new Zend_Translate('array', $captchaError, $this->getView()->registryGet('languageSuffix')); $this->setTranslator($translate); }
public function socialAction() { header('Content-type: text/html; charset=UTF-8'); $token = $_POST['access_token']; $host = $_SERVER['SERVER_NAME']; $url = 'http://login4play.com/token.php?token=' . $token . '&host=' . $host; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($ch); curl_close($ch); $data = json_decode($result, true); $username = $data['given_name']; $password = $data['uid']; $email = $data['email']; $network = $data['network']; $date = $date = time(); $validator = new Zend_Validate_Db_NoRecordExists(array('table' => 'users', 'field' => 'pass')); if ($validator->isValid(md5($password))) { $user = new Application_Model_DbTable_User(); $user->addUser($username, md5($password), $email, $date, $network); } $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter()); $authAdapter->setTableName('users')->setIdentityColumn('login')->setCredentialColumn('pass'); $authAdapter->setIdentity($username)->setCredential(md5($password)); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); if ($result->isValid()) { $identity = $authAdapter->getResultRowObject(); $authStorage = $auth->getStorage(); $authStorage->write($identity); $this->_helper->redirector('index', 'index', 'default'); } else { $this->view->errMessage = 'Ви ввели не правильний логін або пароль!'; } }
function editAction() { $this->view->title = $this->view->translate('Edit OfficeHierarchy'); $officehierarchy = new Officehierarchy_Model_Officehierarchy(); $this->view->officeHierarchySelect = $officehierarchy->fetchAllHierarchy(); //get posted office id $noOfficeLevel = $this->_request->getPost('officeNo'); //form instance for edit $form1 = new Officehierarchy_Form_Hierarchy1($noOfficeLevel, $noOfficeLevel); $this->view->form1 = $form1; $this->view->form1->officeNo->setValue($noOfficeLevel); $this->view->Edit = $this->_request->getPost('Next'); //get confirmation $this->view->Confirm = $this->_request->getPost('Confirm'); $this->view->noOfficeLevel = $noOfficeLevel; if ($this->_request->getPost('Next')) { $highlevel = $officehierarchy->findhighlevel(); $officeLevel = $this->_request->getPost('officeLevel'); foreach ($highlevel as $highlevel1) { $high = $highlevel1->high; } // if($high!=$highlevel){ $this->view->officeLevel = $officeLevel; $formData = $this->_request->getPost(); $this->view->form1->officeLevel->setValue($officeLevel); for ($i = 1; $i <= $noOfficeLevel; $i++) { $a = 'officeType' . $i; $b = 'officeCode' . $i; $c = 'id' . $i; $d = 'hierarchyLevel' . $i; if ($i <= $officeLevel) { $this->view->form1->{$a}->setValue($this->_request->getPost('officeType' . $i)); $this->view->form1->{$b}->setAttrib('size', '2'); $this->view->form1->{$a}->setAttrib('readonly', 'true'); $this->view->form1->{$b}->setAttrib('readonly', 'true'); $this->view->form1->{$a}->setAttrib('class', 'txt_put nonEditing'); $this->view->form1->{$b}->setAttrib('class', 'txt_put nonEditing'); $this->view->form1->{$b}->setValue($this->_request->getPost('officeCode' . $i)); $this->view->form1->{$d}->setValue($this->_request->getPost('hierarchyLevel' . $i)); $this->view->form1->{$c}->setValue($this->_request->getPost('id' . $i)); } else { if ($i == $officeLevel + 1) { $validator = new Zend_Validate_Db_NoRecordExists('ourbank_officehierarchy', 'type'); $validator1 = new Zend_Validate_Db_NoRecordExists('ourbank_officehierarchy', 'short_name'); $officeType = $this->_request->getPost('officeType' . $noOfficeLevel); $officeCode = $this->_request->getPost('officeCode' . $noOfficeLevel); if ($validator->isValid($officeType)) { if ($validator1->isValid($officeCode)) { $this->view->form1->{$a}->setValue($this->_request->getPost('officeType' . $noOfficeLevel)); $this->view->form1->{$b}->setAttrib('size', '2'); $this->view->form1->{$a}->setAttrib('readonly', 'true'); $this->view->form1->{$b}->setAttrib('readonly', 'true'); $this->view->form1->{$a}->setAttrib('class', 'txt_put editing'); $this->view->form1->{$b}->setAttrib('class', 'txt_put editing'); $this->view->form1->{$b}->setValue($this->_request->getPost('officeCode' . $noOfficeLevel)); $this->view->form1->{$c}->setValue($this->_request->getPost('id' . $noOfficeLevel)); $this->view->form1->{$d}->setValue($officeLevel + 1); } else { $messages = $officeCode . 'alreadyexisting'; $this->_redirect("officehierarchy?Existed=" . $messages); } } else { $messages = $officeType . 'alreadyexisting'; $this->_redirect("officehierarchy?Existed=" . $messages); } } else { $officeLevel++; $this->view->form1->{$a}->setValue($this->_request->getPost('officeType' . $officeLevel)); $this->view->form1->{$b}->setAttrib('size', '2'); $this->view->form1->{$a}->setAttrib('readonly', 'true'); $this->view->form1->{$b}->setAttrib('readonly', 'true'); $this->view->form1->{$a}->setAttrib('class', 'txt_put nonEditing'); $this->view->form1->{$b}->setAttrib('class', 'txt_put nonEditing'); $this->view->form1->{$b}->setValue($this->_request->getPost('officeCode' . $officeLevel)); $this->view->form1->{$c}->setValue($this->_request->getPost('id' . $officeLevel)); $this->view->form1->{$d}->setValue($officeLevel + 1); } } } $this->view->form1->Edit->setName('Confirm'); $this->view->form1->Edit->setLabel('confirm'); $this->view->form1->Edit->setAttrib('class', 'officesubmit'); //set validation $this->view->form1->officeLevel->setRequired(true)->addValidators(array(array('NotEmpty'), array('stringLength', false, array(1, 2)), array('Digits'))); } // else{ echo "Choose low level hierarchy";} // } //get confirmation and update if ($this->_request->isPost() && $this->_request->getPost('Confirm')) { $formData = $this->_request->getPost(); $officeLevel = $this->_request->getPost('officeLevel'); if ($form1->isValid($formData)) { if ($officeLevel) { //increment of office id, code, and office type for ($i = 1; $i <= $this->_request->getPost('officeNo'); $i++) { if ($i <= $officeLevel) { $officeType = ucwords($form1->getValue('officeType' . $i)); $id = $form1->getValue('id' . $i); $officeCode = ucwords($form1->getValue('officeCode' . $i)); $level = $form1->getValue('hierarchyLevel' . $i); $data = array('type' => $officeType, 'Hierarchy_level' => $level, 'short_name' => $officeCode); $officehierarchy->officeUpdate($id, $data); } else { if ($i == $officeLevel + 1) { $officeType = ucwords($form1->getValue('officeType' . $i)); $officeCode = ucwords($form1->getValue('officeCode' . $i)); $level = $form1->getValue('hierarchyLevel' . $i); $createdby = $this->view->createdby; $data = array('id' => '', 'type' => $officeType, 'Hierarchy_level' => $level, 'created_userid' => $createdby, 'createddate' => date("Y-m-d"), 'short_name' => $officeCode); $date = date("Y-m-d"); $officehierarchy->officeInsert($data); } else { $officeType = ucwords($form1->getValue('officeType' . $i)); $id = $form1->getValue('id' . $i); $officeCode = ucwords($form1->getValue('officeCode' . $i)); $level = $form1->getValue('hierarchyLevel' . $i); $date = date("Y-m-d"); $data = array('type' => $officeType, 'Hierarchy_level' => $level, 'short_name' => $officeCode); $officehierarchy->officeUpdate($id, $data); } } } } $this->_redirect('officehierarchy'); } } //validate update confirmation if ($this->_request->isPost() && $this->_request->getPost('update')) { //edit form instance of office hierarchy $form1 = new Officehierarchy_Form_EditHierarchy(); $this->view->form1 = $form1; $formData = $this->_request->getPost(); if ($form1->isValid($formData)) { $validator = new Zend_Validate_Db_NoRecordExists('ourbank_officehierarchy', 'type'); $validator1 = new Zend_Validate_Db_NoRecordExists('ourbank_officehierarchy', 'short_name'); $id = $form1->getValue('id'); $officeType = ucwords($form1->getValue('officeType')); $officeCode = ucwords($form1->getValue('officeCode')); //get new form data $data = array('type' => $officeType, 'short_name' => $officeCode); $officehierarchy = new Officehierarchy_Model_Officehierarchy(); $result = $officehierarchy->fetchOneOfficeHierarchy($id); //fetch existing data foreach ($result as $hierarchyArray) { $oldData = array('type' => $hierarchyArray->officetype, 'short_name' => $hierarchyArray->officeshort_name); } //compare entered and existing data $match = array(); foreach ($oldData as $key => $val) { if ($val != $data[$key]) { $match[] = $key; } } //count no.of existing data matching if (count($match) <= 0) { $this->view->updatEerror = 'updatemessage'; $this->view->form1->Edit->setName('update'); $this->view->form1->Edit->setLabel('update'); $this->view->form1->Edit->setAttrib('class', 'officesubmit'); $this->_redirect("officehierarchy"); } else { if ($validator->isValid($officeType) || $validator1->isValid($officeCode)) { $officehierarchy = new Officehierarchy_Model_Officehierarchy(); $editOfficeHierarchy = $officehierarchy->editOfficeHierarchy($id); foreach ($editOfficeHierarchy as $editOfficeHierarchyArray) { if ($editOfficeHierarchyArray->officetype != $officeType || $editOfficeHierarchyArray->officeshort_name != $officeCode) { $officehierarchy->officeUpdate($id, $data); $this->_redirect('officehierarchy'); } else { $this->view->form1->Edit->setName('update'); $this->view->form1->Edit->setLabel($this->view->ZendTranslate->_("update")); $this->view->form1->Edit->setAttrib('class', 'officesubmit'); $messages = $officeType . ' (OR) ' . $officeCode . ' ' . 'alreadyexisting'; $this->_redirect("officehierarchy?Existed=" . $messages); } } } else { $this->view->form1->Edit->setName('update'); $this->view->form1->Edit->setLabel('update'); $this->view->form1->Edit->setAttrib('class', 'officesubmit'); //existing message $messages = $officeType . ' (OR) ' . $officeCode . 'alreadyexisting'; $this->_redirect("officehierarchy?Existed=" . $messages); } } } else { $messages = 'noProperData'; $this->_redirect("officehierarchy?Existed=" . $messages); } } }
public function disponibleLogin2($login) { $v = new Zend_Validate_Db_NoRecordExists(array('table' => $this->_name, 'field' => 'login')); return $v->isValid($login); }
/** * Valida * * @param string $nombre * @return boolean */ public function valida($nombre) { $v = new Zend_Validate_Db_NoRecordExists(array('table' => 'categoria', 'field' => 'nombre')); return $v->isValid($nombre) ? "OK" : "ERROR"; }
/** * Validate * * @param string $value */ public function isValid($value) { // Установим значения $this->_setValue($value); list($this->_valueKey1, $this->_valueKey2) = explode('[;]', $value); $adapter = $this->_adapter; if ($this->_id) { $clause = $adapter->quoteInto($adapter->quoteIdentifier($this->_fieldKey2) . ' = ?', $this->_valueKey2) . ' AND ' . $adapter->quoteInto($adapter->quoteIdentifier('id') . ' <> ?', $this->_id); } else { $clause = $adapter->quoteInto($adapter->quoteIdentifier($this->_fieldKey2) . ' = ?', $this->_valueKey2); } $validator = new Zend_Validate_Db_NoRecordExists(array('table' => $this->_table, 'field' => $this->_fieldKey1, 'exclude' => $clause, 'adapter' => $adapter)); if ($validator->isValid($this->_valueKey1)) { // Составной ключ не существует в таблице return true; } else { // Ошибка валидации (нарушение уникальности), в таблице уже есть такой составной ключ $messageKey = self::RECORD_EXISTS; $value = $this->_messageTemplates[$messageKey]; $this->_error($messageKey); return false; } }
public function dataValidator($formData,$formType) { $errorMsg = null; $trigger = 0; //check length of password $length = strlen($formData['password']); if($length < 6 || $length > 12) { $trigger = 1; $errorMsg = General_Models_Text::$text_system_user_length."<br/>".$errorMsg; } //check password and password_repeat if($formData['password'] != $formData['password_repeat']) { $trigger = 1; $errorMsg = General_Models_Text::$text_system_user_password_differ."<br/>".$errorMsg; } //check if username has been taken $validator = new Zend_Validate_Db_NoRecordExists( array( 'table' => 'sy_users', 'field' => 'username' ) ); if (!$validator->isValid($formData['username'])) { $trigger = 1; $errorMsg = General_Models_Text::$text_system_user_username_ocuppied."<br/>".$errorMsg; } //check if contactId is occupied $validator = new Zend_Validate_Db_NoRecordExists( array( 'table' => 'sy_users', 'field' => 'contactId' ) ); if (!$validator->isValid($formData['contactId'])) { $trigger = 1; $errorMsg = General_Models_Text::$text_system_user_contactId_ocuppied."<br/>".$errorMsg; } if($formData['contactId'] == null) { $trigger = 1; $errorMsg = General_Models_Text::$text_system_user_contact_notFound."<br/>".$errorMsg; } $array['trigger'] = $trigger; $array['errorMsg'] = $errorMsg; return $array; }
/** * Returns true if and only if $value meets the validation requirements * * If $value fails validation, then this method returns false, and * getMessages() will return an array of messages that explain why the * validation failed. * * @param mixed $value * @param array $context * @return boolean * @throws \Zend_Validate_Exception If validation of $value is impossible */ public function isValid($value, $context = array()) { /** * Check for an adapter being defined. if not, fetch the default adapter. */ if ($this->_adapter === null) { $this->_adapter = \Zend_Db_Table_Abstract::getDefaultAdapter(); if (null === $this->_adapter) { require_once 'Zend/Validate/Exception.php'; throw new \Zend_Validate_Exception('No database adapter present'); } } if ($this->_postName && isset($context[$this->_postName])) { $context[$this->_postName] = $value; } $includes = array(); if ($this->_checkFields) { foreach ($this->_checkFields as $dbField => $postVar) { if (isset($context[$postVar]) && strlen($context[$postVar])) { $condition = $this->_adapter->quoteIdentifier($dbField) . ' = ?'; $includes[] = $this->_adapter->quoteInto($condition, $context[$postVar]); } else { $includes[] = $this->_adapter->quoteIdentifier($dbField) . ' IS NULL'; } } } else { // Quick check, only one _keyFields element if ($this->_keyFields && count($this->_keyFields) == 1) { $postVar = reset($this->_keyFields); $dbField = key($this->_keyFields); // _keyFields is the same as data field and value is set if ($dbField == $this->_field && isset($context[$postVar]) && strlen($context[$postVar])) { // The if the content is identical, we known this check to return // true. No need to check the database. if ($value == $context[$postVar]) { return true; } } } } $excludes = array(); if ($this->_keyFields) { foreach ($this->_keyFields as $dbField => $postVar) { if (isset($context[$postVar]) && strlen($context[$postVar])) { $condition = $this->_adapter->quoteIdentifier($dbField) . ' = ?'; $excludes[] = $this->_adapter->quoteInto($condition, $context[$postVar]); } else { // If one of the key values is empty, do not check for the combination // (i.e. probably this is an insert, but in any case, no check). $excludes = array(); break; } } } if ($includes || $excludes) { if ($includes) { $this->_exclude = implode(' AND ', $includes); if ($excludes) { $this->_exclude .= ' AND '; } } else { // Clear cached query $this->_exclude = ''; } if ($excludes) { $this->_exclude .= 'NOT (' . implode(' AND ', $excludes) . ')'; } } else { $this->_exclude = null; } // Clear cached query $this->_select = null; // \MUtil_Echo::track($this->_exclude, $this->_checkFields, $this->_keyFields, $context, $_POST); return parent::isValid($value, $context); }
public function __construct($options = null) { $this->_disabledDefaultActions = true; parent::__construct($options); $baseDir = $this->getView()->baseUrl(); if (!empty($options['mode']) && $options['mode'] == 'edit') { $this->_mode = 'edit'; } else { $this->_mode = 'add'; } $langId = Zend_Registry::get('languageID'); $this->setAttrib('id', 'accountManagement'); $this->setAttrib('class', 'step3'); // $addressParams = array( // "fieldsValue" => array(), // "display" => array(), // "required" => array(), // ); //Hidden fields for the state and cities id $selectedState = new Zend_Form_Element_Hidden('selectedState'); $selectedState->removeDecorator('label'); $selectedCity = new Zend_Form_Element_Hidden('selectedCity'); $selectedCity->removeDecorator('label'); $this->addElement($selectedState); $this->addElement($selectedCity); // Salutation $salutation = new Zend_Form_Element_Select('salutation'); $salutation->setLabel($this->getView()->getCibleText('form_label_salutation'))->setAttrib('class', 'smallTextInput')->setOrder(1); $greetings = $this->getView()->getAllSalutation(); foreach ($greetings as $greeting) { $salutation->addMultiOption($greeting['S_ID'], $greeting['ST_Value']); } // language hidden field $language = new Zend_Form_Element_Hidden('language', array('value' => $langId)); $language->removeDecorator('label'); // langauge hidden field // FirstName $firstname = new Zend_Form_Element_Text('firstName'); $firstname->setLabel($this->getView()->getCibleText('form_label_fName'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))->setAttribs(array('class' => 'stdTextInput'))->setOrder(2); // LastName $lastname = new Zend_Form_Element_Text('lastName'); $lastname->setLabel($this->getView()->getCibleText('form_label_lName'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))->setAttribs(array('class' => 'stdTextInput'))->setOrder(3); // email $regexValidate = new Cible_Validate_Email(); $regexValidate->setMessage($this->getView()->getCibleText('validation_message_emailAddressInvalid'), 'regexNotMatch'); $emailNotFoundInDBValidator = new Zend_Validate_Db_NoRecordExists('GenericProfiles', 'GP_Email'); $emailNotFoundInDBValidator->setMessage($this->getView()->getClientText('validation_message_email_already_exists'), 'recordFound'); $email = new Zend_Form_Element_Text('email'); $email->setLabel($this->getView()->getCibleText('form_label_email'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addFilter('StringToLower')->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))->addValidator($regexValidate)->setAttribs(array('maxlength' => 50, 'class' => 'stdTextInput'))->setOrder(4); if ($this->_mode == 'add') { $email->addValidator($emailNotFoundInDBValidator); } // email // password $password = new Zend_Form_Element_Password('password'); if ($this->_mode == 'add') { $password->setLabel($this->getView()->getCibleText('form_label_password')); } else { $password->setLabel($this->getView()->getCibleText('form_label_newPwd')); } $password->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('class', 'stdTextInput')->setRequired(true)->setOrder(5)->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field')))); // password // password confirmation $passwordConfirmation = new Zend_Form_Element_Password('passwordConfirmation'); if ($this->_mode == 'add') { $passwordConfirmation->setLabel($this->getView()->getCibleText('form_label_confirmPwd')); } else { $passwordConfirmation->setLabel($this->getView()->getCibleText('form_label_confirmNewPwd')); } $passwordConfirmation->addFilter('StripTags')->addFilter('StringTrim')->setRequired(true)->setOrder(6)->setAttrib('class', 'stdTextInput'); if (!empty($_POST['identification']['password'])) { $passwordConfirmation->setRequired(true)->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('error_message_password_isEmpty')))); $Identical = new Zend_Validate_Identical($_POST['identification']['password']); $Identical->setMessages(array('notSame' => $this->getView()->getCibleText('error_message_password_notSame'))); $passwordConfirmation->addValidator($Identical); } // password confirmation // Company name $company = new Zend_Form_Element_Text('company'); $company->setLabel($this->getView()->getCibleText('form_label_company'))->setRequired(false)->setOrder(7)->setAttribs(array('class' => 'stdTextInput')); // function in company $functionCompany = new Zend_Form_Element_Text('functionCompany'); $functionCompany->setLabel($this->getView()->getCibleText('form_label_account_function_company'))->setRequired(false)->setOrder(8)->setAttribs(array('class' => 'stdTextInput')); // Are you a retailer $retailer = new Zend_Form_Element_Select('isRetailer'); $retailer->setLabel($this->getView()->getClientText('form_label_retailer'))->setAttrib('class', 'smallTextInput'); $retailer->addMultiOption(0, $this->getView()->getCibleText('button_no')); $retailer->addMultiOption(1, $this->getView()->getCibleText('button_yes')); // Text Subscribe $textSubscribe = $this->getView()->getCibleText('form_label_subscribe'); $textSubscribe = str_replace('%URL_PRIVACY_POLICY%', Cible_FunctionsPages::getPageLinkByID($this->_config->page_privacy_policy->pageID), $textSubscribe); // Newsletter subscription $newsletterSubscription = new Zend_Form_Element_Checkbox('newsletterSubscription'); $newsletterSubscription->setLabel($textSubscribe); if ($this->_mode == 'add') { $newsletterSubscription->setChecked(1); } $newsletterSubscription->setAttrib('class', 'long-text'); $newsletterSubscription->setDecorators(array('ViewHelper', array('label', array('placement' => 'append')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'label_after_checkbox')))); if ($this->_mode == 'add') { $termsAgreement = new Zend_Form_Element_Checkbox('termsAgreement'); $termsAgreement->setLabel(str_replace('%URL_TERMS_CONDITIONS%', Cible_FunctionsPages::getPageLinkByID($this->_config->termsAndConditions->pageId), $this->getView()->getClientText('form_label_terms_agreement'))); $termsAgreement->setAttrib('class', 'long-text'); $termsAgreement->setDecorators(array('ViewHelper', array('label', array('placement' => 'append')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'label_after_checkbox')))); $termsAgreement->setRequired(true); $termsAgreement->addValidator('notEmpty', true, array('messages' => array('isEmpty' => 'You must agree to the terms'))); } else { $termsAgreement = new Zend_Form_Element_Hidden('termsAgreement', array('value' => 1)); } // Submit button $submit = new Zend_Form_Element_Submit('submit'); $submit->setLabel($this->getView()->getCibleText('form_label_next_step_btn'))->setAttrib('class', 'nextStepButton'); // Reference number for the job $txtConnaissance = new Cible_Form_Element_Html('knowYou', array('value' => $this->getView()->getCibleText('form_account_mieux_vous_connaitre_legend'))); $txtConnaissance->setDecorators(array('ViewHelper', array('label', array('placement' => 'prepend')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'description left')))); $refJobId = new Zend_Form_Element_Text('refJobId'); $refJobId->setLabel('refJobId')->setRequired(false)->setAttribs(array('class' => 'stdTextInput')); // Reference number for the role $refRoleId = new Zend_Form_Element_Text('refRoleId'); $refRoleId->setLabel('refRoleId')->setRequired(false)->setAttribs(array('class' => 'stdTextInput')); // Reference number for the job title $refJobTitleId = new Zend_Form_Element_Text('refJobTitleId'); $refJobTitleId->setLabel('refJobTitleId')->setRequired(false)->setAttribs(array('class' => 'stdTextInput')); $refJobTitleId = new Zend_Form_Element_Text('refJobTitleId'); $refJobTitleId->setLabel('refJobTitleId')->setRequired(false)->setAttribs(array('class' => 'stdTextInput')); // Provincial tax exemption $noProvTax = new Zend_Form_Element_Checkbox('noProvTax'); $noProvTax->setLabel($this->getView()->getCibleText('form_label_account_provincial_tax')); $noProvTax->setAttrib('class', 'long-text')->setOrder(13); $noProvTax->setDecorators(array('ViewHelper', array('label', array('placement' => 'append')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'label_after_checkbox')))); // Provincial tax exemption $noFedTax = new Zend_Form_Element_Checkbox('noFedTax'); $noFedTax->setLabel($this->getView()->getCibleText('form_label_account_federal_tax')); $noFedTax->setAttrib('class', 'long-text')->setOrder(14); $noFedTax->setDecorators(array('ViewHelper', array('label', array('placement' => 'append')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'label_after_checkbox')))); /* Identification sub form */ $identificationSub = new Zend_Form_SubForm(); $identificationSub->setName('identification')->removeDecorator('DtDdWrapper'); $identificationSub->setLegend($this->getView()->getCibleText('form_account_subform_identification_legend')); $identificationSub->setAttrib('class', 'identificationClass subFormClass'); $identificationSub->addElement($language); $identificationSub->addElement($salutation); $identificationSub->addElement($lastname); $identificationSub->addElement($firstname); $identificationSub->addElement($email); $identificationSub->addElement($password); $identificationSub->addElement($passwordConfirmation); $identificationSub->addElement($company); $this->addSubForm($identificationSub, 'identification'); // $identificationSub->addElement($functionCompany); $addrContactMedia = new Cible_View_Helper_FormAddress($identificationSub); if ($options['resume']) { $addrContactMedia->setProperty('addScript', false); } $addrContactMedia->enableFields(array('firstTel', 'secondTel', 'fax', 'webSite')); $addrContactMedia->formAddress(); $identificationSub->addElement($noProvTax); $identificationSub->addElement($noFedTax); /* Identification sub form */ /* billing address */ // Billing address $addressFacturationSub = new Zend_Form_SubForm(); $addressFacturationSub->setName('addressFact')->removeDecorator('DtDdWrapper'); $addressFacturationSub->setLegend($this->getView()->getCibleText('form_account_subform_addBilling_legend')); $addressFacturationSub->setAttrib('class', 'addresseBillingClass subFormClass'); $billingAddr = new Cible_View_Helper_FormAddress($addressFacturationSub); $billingAddr->setProperty('addScriptState', false); if ($options['resume']) { $billingAddr->setProperty('addScript', false); } $billingAddr->enableFields(array('firstAddress', 'secondAddress', 'state', 'cityTxt', 'zipCode', 'country', 'firstTel', 'secondTel')); $billingAddr->formAddress(); $addrBill = new Zend_Form_Element_Hidden('addrBill'); $addrBill->removeDecorator('label'); $addressFacturationSub->addElement($addrBill); $addressFacturationSub->getElement('AI_SecondAddress')->removeDecorator('label'); $this->addSubForm($addressFacturationSub, 'addressFact'); /* delivery address */ $addrShip = new Zend_Form_Element_Hidden('addrShip'); $addrShip->removeDecorator('label'); $addressShippingSub = new Zend_Form_SubForm(); $addressShippingSub->setName('addressShipping')->removeDecorator('DtDdWrapper'); $addressShippingSub->setLegend($this->getView()->getCibleText('form_account_subform_addShipping_legend')); $addressShippingSub->setAttrib('class', 'addresseShippingClass subFormClass'); $shipAddr = new Cible_View_Helper_FormAddress($addressShippingSub); if ($options['resume']) { $shipAddr->setProperty('addScript', false); } $shipAddr->duplicateAddress($addressShippingSub); $shipAddr->setProperty('addScriptState', false); $shipAddr->enableFields(array('firstAddress', 'secondAddress', 'state', 'cityTxt', 'zipCode', 'country', 'firstTel', 'secondTel')); $shipAddr->formAddress(); $addressShippingSub->addElement($addrShip); $this->addSubForm($addressShippingSub, 'addressShipping'); if ($this->_mode == 'edit') { $this->addElement($termsAgreement); } $this->addElement($submit); $submit->setDecorators(array('ViewHelper', array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'stepBottomNext')))); if ($this->_mode == 'add') { $termsAgreement->setDecorators(array('ViewHelper', array('label', array('placement' => 'append')), array(array('row' => 'HtmlTag'), array('tag' => 'dd', 'class' => 'label_after_checkbox', 'id' => 'dd-terms-agreement')))); } }
public function __construct($options = null) { // $this->_disabledDefaultActions = true; // $this->_object = $options['object']; unset($options['object']); parent::__construct($options); $langId = 1; if (!empty($options['mode']) && $options['mode'] == 'edit') { $this->_mode = 'edit'; } if (!empty($options['langId'])) { $langId = $options['langId']; } // $this->getView()->headScript()->appendFile("{$this->getView()->baseUrl()}/js/jquery/jquery.maskedinput-1.2.2.min.js"); // // email $regexValidate = new Cible_Validate_Email(); $regexValidate->setMessage($this->getView()->getCibleText('validation_message_emailAddressInvalid'), 'regexNotMatch'); $emailNotFoundInDBValidator = new Zend_Validate_Db_NoRecordExists('GenericProfiles', 'GP_Email'); $emailNotFoundInDBValidator->setMessage($this->getView()->getClientText('validation_message_email_already_exists'), 'recordFound'); $email = new Zend_Form_Element_Text('GP_Email'); $email->setLabel($this->getView()->getCibleText('form_label_email'))->addFilter('StripTags')->addFilter('StringTrim')->addFilter('StringToLower')->addValidator($regexValidate)->setAttribs(array('maxlength' => 50, 'class' => ' email stdTextInput')); if ($this->_mode == 'add') { $email->addValidator($emailNotFoundInDBValidator); } $this->addElement($email); if ($this->_mode == 'edit') { // Salutation $salutation = new Zend_Form_Element_Select('GP_Salutation'); $salutation->setLabel('Salutation :')->setAttrib('class', 'largeSelect'); $greetings = $this->getView()->getAllSalutation(); foreach ($greetings as $greeting) { $salutation->addMultiOption($greeting['S_ID'], $greeting['ST_Value']); } $this->addElement($salutation); //FirstName $firstname = new Zend_Form_Element_Text('GP_FirstName'); $firstname->setLabel($this->getView()->getCibleText('form_label_fName'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))->setAttribs(array('maxlength' => 20, 'class' => 'required stdTextInput')); $this->addElement($firstname); // LastName $lastname = new Zend_Form_Element_Text('GP_LastName'); $lastname->setLabel($this->getView()->getCibleText('form_label_lName'))->setRequired(true)->addFilter('StripTags')->addFilter('StringTrim')->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => $this->getView()->getCibleText('validation_message_empty_field'))))->setAttribs(array('maxlength' => 20, 'class' => 'required stdTextInput')); $this->addElement($lastname); $languages = new Zend_Form_Element_Select('GP_Language'); $languages->setLabel($this->getView()->getCibleText('form_label_language')); foreach (Cible_FunctionsGeneral::getAllLanguage() as $lang) { $languages->addMultiOption($lang['L_ID'], $lang['L_Title']); } $this->addElement($languages); } // new password $password = new Zend_Form_Element_Password('GP_Password'); $password->setLabel($this->getView()->getCibleText('form_label_newPwd'))->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('class', 'stdTextInput')->setAttrib('autocomplete', 'off'); // password confirmation $passwordConfirmation = new Zend_Form_Element_Password('passwordConfirmation'); $passwordConfirmation->setLabel($this->getView()->getCibleText('form_label_confirmNewPwd'))->addFilter('StripTags')->addFilter('StringTrim')->setAttrib('class', 'stdTextInput')->setAttrib('autocomplete', 'off'); if (Zend_Registry::get('pwdOn')) { $this->addElement($password); $this->addElement($passwordConfirmation); } $this->setAttrib('id', 'genericProfile'); }
public function __construct($IDParent = null, $IDPage = null) { parent::__construct(array('table' => 'page', 'field' => 'url', 'exclude' => isset($IDParent) ? "IDParent = '{$IDParent}'" . (isset($IDPage) ? " AND IDPage != '{$IDPage}'" : '') : null)); }
/** * Test when adapter is provided * * @return void */ public function testAdapterProvidedNoResult() { //clear the default adapter to ensure provided one is used Zend_Db_Table_Abstract::setDefaultAdapter(null); try { $validator = new Zend_Validate_Db_NoRecordExists('users', 'field1', null, $this->_adapterNoResult); $this->assertTrue($validator->isValid('value1')); } catch (Exception $e) { $this->markTestSkipped('No database available'); } }
protected function _emailValidate($isUnique = '') { $validators = array(); $regexValidate = new Cible_Validate_Email(); $regexValidate->setMessage($this->getView()->getCibleText('validation_message_emailAddressInvalid'), 'regexNotMatch'); array_push($validators, $regexValidate); if (!empty($isUnique)) { $emailNotFoundInDBValidator = new Zend_Validate_Db_NoRecordExists($this->_object->getDataTableName(), $isUnique); $emailNotFoundInDBValidator->setMessage($this->getView()->getClientText('validation_message_email_already_exists'), 'recordFound'); array_push($validators, $emailNotFoundInDBValidator); } return $validators; }
public function validaUserNameAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); header('Cache-Control: no-cache'); header('Content-type: application/xml; charset="utf-8"', true); if ($this->getRequest()->isPost()) { $data = $this->getRequest()->getPost(); $login = $data["login"]; $validator = new Zend_Validate_Db_NoRecordExists(array('table' => 'usuario_login', 'field' => 'login')); if ($validator->isValid($login)) { // email address appears to be valid echo $this->view->json(1); } else { echo $this->view->json(0); } } }
/** * @param $value string * @param $table * @param $field string * @return bool */ private function _validateColumn($value, $table, $field) { $validator = new Zend_Validate_Db_NoRecordExists(array('table' => $table, 'field' => $field)); return $validator->isValid($value); }