Yii Framework Forum: Cformmodel - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cformmodel Problem dropdown validation Rate Topic: -----

#1 User is offline   mate makhatadze 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 21-November 12

Posted 13 May 2014 - 03:13 AM

<?php

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of CreateClassifiedsForm
*
* @author info_000
*/
class CreateClassifiedsForm extends CFormModel{
//put your code here

public $fields=array();
public $labels=array();
//public $rules;
public $getFields;
public $getLabels;

public function rules()
{
// return array(
// // name, email, subject and body are required
// array('rubrika', 'required'),
// // email has to be a valid email address
// //array('email', 'email'),
// // verifyCode needs to be entered correctly
// //array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
// );
$required = array();
$numerical = array();
$float = array();
$decimal = array();
$rules = array();

$model=self::getFields();
// print_r($model);
foreach ($model as $field) {

$field_rule = array();
if ($field->required==1)
array_push($required,$field->varname);
if ($field->field_type=='FLOAT')
array_push($float,$field->varname);
if ($field->field_type=='DECIMAL')
array_push($decimal,$field->varname);
if ($field->field_type=='INTEGER')
array_push($numerical,$field->varname);
if ($field->field_type=='VARCHAR'||$field->field_type=='TEXT') {
$field_rule = array($field->varname, 'length', 'max'=>$field->field_size, 'min' => $field->field_size_min);
if ($field->error_message) $field_rule['message'] = UserModule::t($field->error_message);
array_push($rules,$field_rule);
}
if ($field->other_validator) {
if (strpos($field->other_validator,'{')===0) {
$validator = (array)CJavaScript::jsonDecode($field->other_validator);
foreach ($validator as $name=>$val) {
$field_rule = array($field->varname, $name);
$field_rule = array_merge($field_rule,(array)$validator[$name]);
if ($field->error_message) $field_rule['message'] = UserModule::t($field->error_message);
array_push($rules,$field_rule);
}
} else {
$field_rule = array($field->varname, $field->other_validator);
if ($field->error_message) $field_rule['message'] = UserModule::t($field->error_message);
array_push($rules,$field_rule);
}
} elseif ($field->field_type=='DATE') {
if ($field->required)
$field_rule = array($field->varname, 'date', 'format' => array('yyyy-mm-dd'));
else
$field_rule = array($field->varname, 'date', 'format' => array('yyyy-mm-dd','0000-00-00'), 'allowEmpty'=>true);

if ($field->error_message) $field_rule['message'] = UserModule::t($field->error_message);
array_push($rules,$field_rule);
}
if ($field->match) {
$field_rule = array($field->varname, 'match', 'pattern' => $field->match);
if ($field->error_message) $field_rule['message'] = UserModule::t($field->error_message);
array_push($rules,$field_rule);
}
if ($field->range) {
$field_rule = array($field->varname, 'in', 'range' => self::rangeRules($field->range));
if ($field->error_message) $field_rule['message'] = UserModule::t($field->error_message);
array_push($rules,$field_rule);
}
}

if(!empty($required)) array_push($rules,array(implode(',',$required), 'required'));
if(!empty($numerical)) array_push($rules,array(implode(',',$numerical), 'numerical', 'integerOnly'=>true));
if(!empty($float)) array_push($rules,array(implode(',',$float), 'type', 'type'=>'float'));
if(!empty($decimal)) array_push($rules,array(implode(',',$decimal), 'match', 'pattern' => '/^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$/'));
// array_push($rules,array(implode(',',$required), 'safe'));
return $rules;
}
public function attributeLabels()
{
return
self::getLabels();

}
public function __get($name)
{
if (isset($this->$name))
return $this->$name;
else
return '';
}

public function __set($name, $value)
{
$this->$name = $value;
}

public static function getFields() {

$fields = Categories::model()->findAllByAttributes(array('extension'=>'cfilter','hide'=>0));
$fd=array();
foreach($fields as $field){
$comFields=new stdClass();
$fparams=json_decode($field->params);
list($s) = ClassifiedsFields::getWidgetsParams($field->metadata);
$ex = $field->metadata;
$params = (object)$s[$ex];
$comFields->varname= IwFunctions::FromGeo($field->name);
// $comFields->varname= IwFunctions::FromGeo($field->name);
$comFields->field_type=$params->field_type;
$comFields->required=$fparams->required;
//$comFields->required=
// $comFields[]=array_merge($field,$s);

$fd[]=$comFields;
}
//$this->fields = $fd;
return $fd;

}
public static function getLabels() {

$fields = Categories::model()->findAllByAttributes(array('extension'=>'cfilter','hide'=>0));
$fd=array();
foreach($fields as $field){
$fd[IwFunctions::FromGeo($field->name)]=$field->name;
}
return $fd;

}
public function init() {

$this->getFields=self::getFields();
$this->getLabels=self::getLabels();

}
}

?>
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users