public function _validation_requiredLang($val) {
die("field".$this->active_field());
$field = Validation::active_field();
$idLanguage = substr($field, strlen($field)-1, strlen($field));
if( is_int($idLanguage) ){
$lang = Model_RegistrantLanguage::query()->where('idLanguage', $idLanguage)->where('active', 1)->get_one();
if( $lang && $this->_empty($val) ) return false;
}
return true;
}
I extended the validation class and added it to the autoloader in the bootstrap files
Autoloader::add_classes(array(
// Add classes you want to override here
// Example: 'View' => APPPATH.'classes/view.php',
'Validation' => APPPATH.'classes/core/validation.php',
'Log' => APPPATH.'classes/core/log.php',
));
My class in classes/core/validation.php:
class Validation extends Fuel\Core\Validation {
/**
* Required validation for translatable fields
*/
public function _validation_requiredLang($val) {
die("field=".$this->active_field());
$field = $this->active_field();
$idLanguage = substr($field, strlen($field)-1, strlen($field));
if( is_int($idLanguage) ){
$lang = Model_RegistrantLanguage::query()->where('idLanguage', $idLanguage)->where('active', 1)->get_one();
if( $lang && $this->_empty($val) ) return false;
}
return true;
}
}
public function save($cascade = null, $use_transaction = false)
{
// get active Languages and check required translatable fields
$activeLanguages = array();
foreach( Model_Language::getActiveLanguages() as $lang ) $activeLanguages[] = $lang->idLanguage;
foreach( self::properties() as $field => $property ){
if( isset($property['validation']) && in_array('requiredLang', $property['validation']) &&
in_array(substr($field, strlen($field)-1, strlen($field)), $activeLanguages) && empty($this->$field) ){
throw new Orm\ValidationFailed('Please fill all mandatory fields');
}
}
return parent::save($cascade, $use_transaction);
}
It looks like you're new here. If you want to get involved, click one of these buttons!