Jump to content

Dni (Identification Number) Enabled But Not Mandatory. Empty Records Allowed.


Recommended Posts

Hello everybody,

 

i am trying to make the dni (identification number) not mandatory for the countries where is enabled. The purpose is to allow for recording either empty values or valid values only. So changing the code of the address.tpl i managed to show the text field and it is not mandatory, so it can be left not filled in. But when i post i real value inside, the record is not send to database and it is not recorded.

So i have decided to make it another way. I have made one custom additional public function in the Tools.php file that checks the value of the field dni, only if it is not empty:

 

public static function getIdentValue($key, $default_value = false)
{
if (strval($key) != null && !empty($key) && strval($key) != '')
{
$ret = (isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? $_GET[$key] : $default_value));
 
if (is_string($ret) === true)
$ret = urldecode(preg_replace('/((\%5C0+)|(\%00+))/i', '', urlencode($ret)));
return !is_string($ret)? $ret : stripslashes($ret);
}
else{
return true;
}
 
 
and also changed the code inside AdminAdressesControler to make the check of the value through this custom function in Tools:
 
if (Country::isNeedDniByCountryId(Tools::getValue('id_country')) && !Tools::getIdentValue('dni'))
$this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
 
But still the check is not successful and if i left the field empty, an error is raised and does not allow me to save empty value in the db. Even after clearing the cache - deleting class_index. Same result.
 
So i have decided after all to skip the logic of dni empty value check directly before this check in Tools.php and have added additional emtpy value check directly before the Tools check in the AdminAdressesControler. So here is like it looks like:
 
if (Country::isNeedDniByCountryId(Tools::getValue('id_country')))       
if ((strval('dni') != '') && (strval('dni') != null))
{
if (!Tools::getValue('dni'))
$this->errors[] = Tools::displayError('The identification number is incorrect or has already been used.');
}
 
So it should avoid the check from the Tools::getValue function if the field 'dni' is empty. But actually it does check it and an empty field could not be recorded. So i have made a change in the message error : "The identification number is incorrect or has already been used" raised by this function, so i can see where the message is raised from. Surprisingly the message error when i have tried to save an empty dni field didn't change. the controller in in override/controlers/admin, so i have deleted the cache, but still the same result. So it means that there is also another function that checks the field dni and i do not know where it is.
Can you please inform me how can i make this field enabled for unique dni numbers and empty values also. I have check the table in the database, where the field dni is allowed to be null, or whatever - it is even not unique field. 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...