// Small changes on validateController

This commit is contained in:
rGaillard
2012-01-02 10:09:36 +00:00
parent 227ee1a5d0
commit e2e11ae580
4 changed files with 66 additions and 90 deletions
+22 -22
View File
@@ -109,28 +109,28 @@ class AddressCore extends ObjectModel
'table' => 'address', 'table' => 'address',
'primary' => 'id_address', 'primary' => 'id_address',
'fields' => array( 'fields' => array(
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'), 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_from_front' => false),
'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'), 'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_from_front' => false),
'id_supplier' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'), 'id_supplier' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_from_front' => false),
'id_warehouse' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'), 'id_warehouse' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_from_front' => false),
'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true, 'copy_from_front' => true),
'id_state' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'), 'id_state' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_from_front' => true),
'alias' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32), 'alias' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32, 'copy_from_front' => true),
'company' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 32), 'company' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 32, 'copy_from_front' => true),
'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32), 'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32, 'copy_from_front' => true),
'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32), 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32, 'copy_from_front' => true),
'vat_number' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName'), 'vat_number' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'copy_from_front' => true),
'address1' => array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128), 'address1' => array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'required' => true, 'size' => 128, 'copy_from_front' => true),
'address2' => array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128), 'address2' => array('type' => self::TYPE_STRING, 'validate' => 'isAddress', 'size' => 128, 'copy_from_front' => true),
'postcode' => array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12), 'postcode' => array('type' => self::TYPE_STRING, 'validate' => 'isPostCode', 'size' => 12, 'copy_from_front' => true),
'city' => array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64), 'city' => array('type' => self::TYPE_STRING, 'validate' => 'isCityName', 'required' => true, 'size' => 64, 'copy_from_front' => true),
'other' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300), 'other' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'size' => 300, 'copy_from_front' => true),
'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 16), 'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 16, 'copy_from_front' => true),
'phone_mobile' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 16), 'phone_mobile' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 16, 'copy_from_front' => true),
'dni' => array('type' => self::TYPE_STRING, 'validate' => 'isDniLite', 'size' => 16), 'dni' => array('type' => self::TYPE_STRING, 'validate' => 'isDniLite', 'size' => 16, 'copy_from_front' => true),
'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_from_front' => false),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_from_front' => false),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat', 'copy_from_front' => false),
), ),
); );
+29 -29
View File
@@ -152,35 +152,35 @@ class CustomerCore extends ObjectModel
'table' => 'customer', 'table' => 'customer',
'primary' => 'id_customer', 'primary' => 'id_customer',
'fields' => array( 'fields' => array(
'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5'), 'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5', 'copy_from_front' => false),
'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32), 'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32, 'copy_from_front' => true),
'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32), 'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32, 'copy_from_front' => true),
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128), 'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'required' => true, 'size' => 128, 'copy_from_front' => true),
'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 32), 'passwd' => array('type' => self::TYPE_STRING, 'validate' => 'isPasswd', 'required' => true, 'size' => 32, 'copy_from_front' => true),
'last_passwd_gen' => array('type' => self::TYPE_STRING), 'last_passwd_gen' => array('type' => self::TYPE_STRING, 'copy_from_front' => false),
'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_from_front' => true),
'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate'), 'birthday' => array('type' => self::TYPE_DATE, 'validate' => 'isBirthDate', 'copy_from_front' => true),
'newsletter' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'newsletter' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_from_front' => true),
'newsletter_date_add' => array('type' => self::TYPE_DATE), 'newsletter_date_add' => array('type' => self::TYPE_DATE,'copy_from_front' => false),
'ip_registration_newsletter' => array('type' => self::TYPE_STRING), 'ip_registration_newsletter' => array('type' => self::TYPE_STRING, 'copy_from_front' => false),
'optin' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'optin' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_from_front' => true),
'website' => array('type' => self::TYPE_STRING, 'validate' => 'isUrl'), 'website' => array('type' => self::TYPE_STRING, 'validate' => 'isUrl', 'copy_from_front' => true),
'company' => array('type' => self::TYPE_STRING, 'validate' => 'isName'), 'company' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'copy_from_front' => true),
'siret' => array('type' => self::TYPE_STRING, 'validate' => 'isSiret'), 'siret' => array('type' => self::TYPE_STRING, 'validate' => 'isSiret', 'copy_from_front' => true),
'ape' => array('type' => self::TYPE_STRING, 'validate' => 'isApe'), 'ape' => array('type' => self::TYPE_STRING, 'validate' => 'isApe', 'copy_from_front' => true),
'outstanding_allow_amount' => array('type' => self::TYPE_INT, 'validate' => 'isFloat'), 'outstanding_allow_amount' => array('type' => self::TYPE_INT, 'validate' => 'isFloat', 'copy_from_front' => false),
'show_public_prices' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'show_public_prices' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_from_front' => false),
'id_risk' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'id_risk' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_from_front' => false),
'max_payment_days' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'max_payment_days' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_from_front' => false),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_from_front' => false),
'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_from_front' => false),
'note' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 65000), 'note' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 65000, 'copy_from_front' => false),
'is_guest' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'is_guest' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_from_front' => false),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_from_front' => false),
'id_group_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), 'id_group_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_from_front' => false),
'id_default_group' => array('type' => self::TYPE_INT), 'id_default_group' => array('type' => self::TYPE_INT, 'copy_from_front' => false),
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_from_front' => false),
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_from_front' => false),
), ),
); );
+15 -18
View File
@@ -759,27 +759,24 @@ abstract class ObjectModelCore
public function validateController($htmlentities = true) public function validateController($htmlentities = true)
{ {
$errors = array(); $errors = array();
foreach ($this->def['fields'] as $field => $data)
/* Checking for required fields */
$fieldsRequired = array_merge($this->fieldsRequired, (isset(self::$fieldsRequiredDatabase[get_class($this)]) ? self::$fieldsRequiredDatabase[get_class($this)] : array()));
foreach ($fieldsRequired AS $field)
if (($value = Tools::getValue($field, $this->{$field})) == false && (string)$value != '0')
if (!$this->id OR $field != 'passwd')
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is required.');
/* Checking for maximum fields sizes */
foreach ($this->fieldsSize AS $field => $maxLength)
if (($value = Tools::getValue($field, $this->{$field})) && Tools::strlen($value) > $maxLength)
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is too long.').' ('.Tools::displayError('Maximum length:').' '.$maxLength.')';
/* Checking for fields validity */
foreach ($this->fieldsValidate AS $field => $function)
{ {
if (!isset($data['copy_from_front']) || !$data['copy_from_front'])
continue;
/* Checking for required fields */
if (isset($data['required']) && $data['required'] && ($value = Tools::getValue($field, $this->{$field})) == false && (string)$value != '0')
if (!$this->id OR $field != 'passwd')
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is required.');
/* Checking for maximum fields sizes */
if (isset($data['size']) && ($value = Tools::getValue($field, $this->{$field})) && Tools::strlen($value) > $data['size'])
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is too long.').' ('.Tools::displayError('Maximum length:').' '.$data['size'].')';
/* Checking for fields validity */
// Hack for postcode required for country which does not have postcodes // Hack for postcode required for country which does not have postcodes
if ($value = Tools::getValue($field, $this->{$field}) OR ($field == 'postcode' AND $value == '0')) if ($value = Tools::getValue($field, $this->{$field}) OR ($field == 'postcode' AND $value == '0'))
{ {
if (!Validate::$function($value) && (!empty($value) || in_array($field, $this->fieldsRequired))) if (isset($data['validate']) && !Validate::$data['validate']($value) && (!empty($value) || $data['required']))
$errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is invalid.'); $errors[] = '<b>'.self::displayFieldName($field, get_class($this), $htmlentities).'</b> '.Tools::displayError('is invalid.');
else else
{ {
@@ -1270,4 +1267,4 @@ abstract class ObjectModelCore
{ {
} }
} }
-21
View File
@@ -44,27 +44,6 @@ class IdentityControllerCore extends FrontController
*/ */
public function postProcess() public function postProcess()
{ {
if (count($_POST))
{
$exclusion = array('secure_key',
'old_passwd',
'passwd',
'active',
'date_add',
'date_upd',
'last_passwd_gen',
'newsletter_date_add',
'id_default_group',
'id_shop',
'id_group_shop',
'ip_registration_newsletter',
'note',
'is_guest');
$fields = $this->customer->getFields();
foreach ($fields as $key => $value)
if (!in_array($key, $exclusion))
$this->customer->{$key} = key_exists($key, $_POST) ? trim($_POST[$key]) : 0;
}
if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days'])) if (isset($_POST['years']) && isset($_POST['months']) && isset($_POST['days']))
$this->customer->birthday = (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days']); $this->customer->birthday = (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days']);