/**
  * Returns the Field Rules, to validate users input
  *
  * @param type $rules
  * @return type
  */
 public function getFieldRules($rules = array())
 {
     $rules[] = array($this->profileField->internal_name, 'numerical');
     if ($this->maxValue) {
         $rules[] = array($this->profileField->internal_name, 'numerical', 'max' => $this->maxValue);
     }
     if ($this->minValue) {
         $rules[] = array($this->profileField->internal_name, 'numerical', 'min' => $this->minValue);
     }
     return parent::getFieldRules($rules);
 }
 public function actionEditField()
 {
     // XSS Protection
     $_POST = Yii::app()->input->stripClean($_POST);
     $id = (int) Yii::app()->request->getQuery('id');
     // Get Base Field
     $field = ProfileField::model()->findByPk($id);
     if ($field == null) {
         $field = new ProfileField();
     }
     // Get all Available Field Class Instances, also bind current profilefield to the type
     $fieldTypes = ProfileFieldType::getTypeInstances($field);
     // Build Form Definition
     $definition = array();
     #$definition['activeForm'] = array(
     #    'class' => 'CActiveForm',
     #    'enableAjaxValidation' => true,
     #    'id' => 'login-form',
     #);
     $definition['elements'] = array();
     // Add all sub forms
     $definition['elements'] = array_merge($definition['elements'], $field->getFormDefinition());
     foreach ($fieldTypes as $fieldType) {
         $definition['elements'] = array_merge($definition['elements'], $fieldType->getFormDefinition());
     }
     // Add Form Buttons
     $definition['buttons'] = array('save' => array('type' => 'submit', 'label' => Yii::t('AdminModule.controllers_UserprofileController', 'Save'), 'class' => 'btn btn-primary'));
     if (!$field->isNewRecord && !$field->is_system) {
         $definition['buttons']['delete'] = array('type' => 'submit', 'label' => Yii::t('AdminModule.controllers_UserprofileController', 'Delete'), 'class' => 'btn btn-danger pull-right');
     }
     // Create Form Instance
     $form = new HForm($definition);
     // Add used models to the CForm, so we can validate it
     $form['ProfileField']->model = $field;
     foreach ($fieldTypes as $fieldType) {
         $form[get_class($fieldType)]->model = $fieldType;
     }
     // Form Submitted?
     if ($form->submitted('save') && $form->validate()) {
         $this->forcePostRequest();
         // Use ProfileField Instance from Form with new Values
         $field = $form['ProfileField']->model;
         $fieldType = $form[$field->field_type_class]->model;
         $field->save();
         $fieldType->save();
         $this->redirect(Yii::app()->createUrl('//admin/userprofile'));
     }
     if ($form->submitted('delete')) {
         $this->forcePostRequest();
         $field->delete();
         $this->redirect(Yii::app()->createUrl('//admin/userprofile'));
     }
     $this->render('editField', array('form' => $form, 'field' => $field));
 }
 /**
  * Returns the Field Rules, to validate users input
  *
  * @param type $rules
  * @return type
  */
 public function getFieldRules($rules = array())
 {
     $rules[] = array($this->profileField->internal_name, 'in', 'range' => array_keys($this->getSelectItems()));
     return parent::getFieldRules($rules);
 }
Beispiel #4
0
 /**
  * Validator which checks the fieldtype
  *
  * Also ensures that field_type_class could not be changed on existing records.
  */
 public function checkType()
 {
     if (!$this->isNewRecord) {
         // Dont allow changes of internal_name - Maybe not the best way to check it.
         $currentProfileField = ProfileField::model()->findByPk($this->id);
         if ($this->field_type_class != $currentProfileField->field_type_class) {
             $this->addError('field_type_class', Yii::t('UserModule.models_ProfileField', 'Field Type could not be changed!'));
         }
     } else {
         if (!key_exists($this->field_type_class, ProfileFieldType::getFieldTypes())) {
             $this->addError('field_type_class', Yii::t('UserModule.models_ProfileField', 'Invalid field type!'));
         }
     }
 }
 /**
  * Returns the Field Rules, to validate users input
  *
  * @param type $rules
  * @return type
  */
 public function getFieldRules($rules = array())
 {
     $rules[] = array($this->profileField->internal_name, 'safe');
     return parent::getFieldRules($rules);
 }
 /**
  * Returns the Field Rules, to validate users input
  *
  * @param type $rules
  * @return type
  */
 public function getFieldRules($rules = array())
 {
     if ($this->validator == self::VALIDATOR_EMAIL) {
         $rules[] = array($this->profileField->internal_name, 'email');
     } elseif ($this->validator == self::VALIDATOR_URL) {
         $rules[] = array($this->profileField->internal_name, 'url');
     }
     if ($this->maxLength == "" || $this->maxLength > 255) {
         $rules[] = array($this->profileField->internal_name, 'length', 'max' => 255);
     } else {
         $rules[] = array($this->profileField->internal_name, 'length', 'max' => $this->maxLength);
     }
     if ($this->minLength != "") {
         $rules[] = array($this->profileField->internal_name, 'length', 'min' => $this->minLength);
     }
     if ($this->regexp != "") {
         $errorMsg = $this->regexpErrorMessage;
         if ($errorMsg == "") {
             $errorMsg = "Invalid!";
         }
         $rules[] = array($this->profileField->internal_name, 'match', 'pattern' => $this->regexp, 'message' => $errorMsg);
     }
     return parent::getFieldRules($rules);
 }
 /**
  * Returns the Field Rules, to validate users input
  *
  * @param type $rules
  * @return type
  */
 public function getFieldRules($rules = array())
 {
     $rules[] = array($this->profileField->internal_name, 'date', 'format' => 'yyyy-MM-dd hh:mm:ss');
     return parent::getFieldRules($rules);
 }