Little change for management better the errors in fields

This commit is contained in:
Antonio de la Rosa 2015-12-17 01:48:11 +01:00
parent 243767bc12
commit 479f449b13
25 changed files with 124 additions and 24 deletions

View file

@ -64,7 +64,7 @@ class CharField extends PhangoField {
}
return Utils::form_text($value);
return $value;
}

View file

@ -84,7 +84,7 @@ class ChoiceField extends PhangoField {
}
else
{
$this->error=1;
return $this->default_value;
}

View file

@ -82,8 +82,8 @@ class DateField extends PhangoField {
if($final_value===false)
{
$final_value=mktime (0, 0, 0, $arr_time[1], $arr_time[2], $arr_time[0] );
$this->error=true;
$final_value=mktime(date('H'), date('i'), date('s'));
}

View file

@ -25,8 +25,20 @@ class DateTimeField extends DateField
$timestamp=parent::check($value);
return date('YmdHis', $timestamp);
$date=@date('YmdHis', $timestamp);
if($date!==false)
{
return date('YmdHis', $timestamp);
}
else
{
$this->error=true;
return date('YmdHis');
}
}
public function search_field($value)

View file

@ -31,6 +31,14 @@ class DoubleField extends PhangoField {
$this->value=Utils::form_text($value);
settype($value, "double");
if($this->value==0 && $this->required==true)
{
$this->error=1;
}
return $value;
}

View file

@ -52,6 +52,8 @@ class EmailField extends PhangoField {
$this->std_error='Email format error';
$this->error=1;
return '';
}

View file

@ -75,6 +75,8 @@ class FileField extends PhangoField {
$this->std_error=I18n::lang('common', 'error_cannot_upload_this_file_to_the_server', 'Error: Cannot upload this file to the server');
$this->error=1;
return '';
}
@ -94,6 +96,8 @@ class FileField extends PhangoField {
$this->std_error=I18n::lang('error_model', 'check_error_enctype_for_upload_file', 'Please, check enctype form of file form');
$this->error=1;
return '';
}

View file

@ -91,7 +91,7 @@ class ForeignKeyField extends IntegerField{
else
{
$this->error=1;
return $this->default_id;

View file

@ -60,7 +60,7 @@ class I18nField extends PhangoField {
{
$this->std_error=I18n::lang('common', 'error_you_need_this_language_field', 'Error, you need this language field').' '.I18n::$language;
$this->error=1;
return '';
}

View file

@ -98,6 +98,9 @@ class ImageField extends PhangoField {
if(!@unlink($this->path.'/'.$prefix.'_'.$base_old_image))
{
// $this->error=true;
$this->std_error=I18n::lang('common', 'cannot_delete_old_image', 'Cannot delete old thumb images, please, check permissions');
}
@ -147,6 +150,8 @@ class ImageField extends PhangoField {
if(!$image->fit($width)->encode('jpg', $this->quality_jpeg)->save($this->path.'/'.$prefix.'_'.$base_name_image.'.jpg'))
{
$this->error=true;
$this->std_error=I18n::lang('common', 'cannot_save_images', 'Cannot save images. Please, check permissions');
}
@ -169,6 +174,8 @@ class ImageField extends PhangoField {
if(!$image->save($this->path.'/'.$name_image))
{
$this->error=1;
$this->std_error=I18n::lang('common', 'cannot_save_images', 'Cannot save images, please, check permissions');
return '';
@ -183,6 +190,8 @@ class ImageField extends PhangoField {
$this->std_error=I18n::lang('common', 'no_valid_image', 'This image is wrong');
$this->error=1;
return '';
}
@ -196,6 +205,8 @@ class ImageField extends PhangoField {
}
$this->error=true;
$this->std_error=I18n::lang('common', 'no_image_found', 'No image uploaded, check enctype form');
return '';

View file

@ -7,6 +7,7 @@
namespace PhangoApp\PhaModels\CoreFields;
use PhangoApp\PhaUtils\Utils;
use PhangoApp\PhaI18n\I18n;
class IntegerField extends PhangoField {
@ -44,15 +45,21 @@ class IntegerField extends PhangoField {
}
if($this->min_num<>0 && $value<$this->min_num)
{
{
$this->std_error=I18n::lang('common', 'no_value', 'The value is wrong. You need a value betwen '.$this->min_num.' and '.$this->max_num);
$this->error=1;
$value=$this->min_num;
}
if($this->max_num<>0 && $value>$this->max_num)
{
$this->std_error=I18n::lang('common', 'no_value', 'The value is wrong. You need a value betwen '.$this->min_num.' and '.$this->max_num);
$this->error=1;
$value=$this->max_num;
}

View file

@ -18,8 +18,10 @@ class IpField extends CharField {
}
else
{
$this->std_error=I18n::lang('common', 'no_valid_ip', 'This ip is not valid');
$this->error=1;
return false;
return "";
}

View file

@ -36,6 +36,7 @@ class KeyField extends PhangoField {
$this->value=Utils::form_text($value);
settype($value, "integer");
return $value;
}

View file

@ -18,8 +18,16 @@ class NormalizeField extends TextField {
public function check($value)
{
$value=$this->check_text($value);
return $this->check_text($value);
if($value=='')
{
$this->error=1;
}
return $value;
}

View file

@ -38,7 +38,7 @@ class ParentField extends IntegerField{
}
else
{
$this->error=1;
return 0;
}

View file

@ -31,7 +31,8 @@ class PasswordField extends CharField {
if($value=='')
{
$this->error=1;
return '';
}
@ -45,6 +46,8 @@ class PasswordField extends CharField {
if(strlen($value)<$this->min_length)
{
$this->error=1;
$this->std_error=I18n::lang('common', 'password_min_length', 'Minimal password length:').' '.$this->min_length;
return '';

View file

@ -18,6 +18,8 @@ class PercentField extends IntegerField{
$this->std_error=i18n_lang('common', 'the_value_can_not_be_greater_than_100', 'The value cannot be greater than 100');
$this->error=1;
return 0;
}

View file

@ -18,6 +18,7 @@ class PhoneField extends CharField{
if(!preg_match('/^[0-9]+$/', $value))
{
$this->error=1;
return '';

View file

@ -53,6 +53,14 @@ class PrimaryField extends PhangoField {
$this->value=Utils::form_text($value);
settype($value, "integer");
if($this->value==0)
{
$this->error=1;
}
return $value;
}

View file

@ -20,8 +20,17 @@ class SlugifyField extends PhangoField {
static function check($value)
{
$value=slugify($value);
return slugify($value);
if($value=='')
{
$this->error=1;
}
return $value;
}
function get_type_sql()

View file

@ -32,7 +32,17 @@ class TextField extends PhangoField {
//Delete Javascript tags and simple quotes.
$this->value=$value;
return Utils::form_text($value, $this->br);
$value=Utils::form_text($value, $this->br);
if($value=='')
{
$this->error=1;
}
return $value;
}

View file

@ -43,6 +43,7 @@ class TextHTMLField extends PhangoField {
if($txt_without_tags=='')
{
$this->error=true;
return '';
}
@ -60,7 +61,16 @@ class TextHTMLField extends PhangoField {
}
return Utils::form_text_html($value, $this->allowedtags);
$value=Utils::form_text_html($value, $this->allowedtags);
if($value=='')
{
$this->error=1;
}
return $value;
}

View file

@ -19,7 +19,9 @@ class UrlField extends CharField {
else
{
return false;
$this->error=1;
return '';
}

View file

@ -62,8 +62,8 @@ class SQLClass {
static public function webtsys_fetch_array( $query ,$assoc_type=0)
{
$arr_assoc[0]=MYSQL_ASSOC;
$arr_assoc[1]=MYSQL_NUM;
$arr_assoc[0]=MYSQLI_ASSOC;
$arr_assoc[1]=MYSQLI_NUM;
$arr_final = mysqli_fetch_array( $query ,$arr_assoc[$assoc_type]);

View file

@ -1844,9 +1844,9 @@ class Webmodel {
//If value isn't valid and is required set error for this component...
if($this->components[$key]->required==1 && $arr_components[$key]=="")
if($this->components[$key]->required==1 && $this->components[$key]->error==1)
{
//Set errors...
if($this->components[$key]->std_error=='')
@ -1906,7 +1906,7 @@ class Webmodel {
}
//If not return values sanitized...
return $arr_components;
}