Jump to content

[SOLVED with style] Include Numerical Characters in name field for registration


glengarry86@hotmail.com

Recommended Posts

Hi Gless,

do this:
edit file /classes/Validate.php
find the code for isName:

/**
* Check for name validity
*
* @param string $name Name to validate
* @return boolean Validity is ok or not
*/
public static function isName($name)
{
return preg_match(Tools::cleanNonUnicodeSupport('/^[^0-9!<>,;?=+()@#"째{}_$%:]*$/u'), stripslashes($name));
}

Copy this block (copy just below itself) and change this (red text) in the copy:


/**
* Check for name validity but allow numbers
*
* @param string $name Name to validate
* @return boolean Validity is ok or not
*/
public static function isNameWithDigits($name)
{
return preg_match(Tools::cleanNonUnicodeSupport('/^[^!<>,;?=+()@#"째{}_$%:]*$/u'), stripslashes($name));
}

(I took out the
'/^[^0-9!<>,;?=+()@#"째{}_$%:]*$/u'
0-9 from the original string)

save the file.

Then edit classes/Customer.php and find: Add red text)
public static $definition = array(
'table' => 'customer',
'primary' => 'id_customer',
'fields' => array(
'secure_key' => array('type' => self::TYPE_STRING, 'validate' => 'isMd5', 'copy_post' => false),
'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isNameWithDigits', 'required' => true, 'size' => 32),
'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),

and save the file

Finally edit file classes/Address.php and find (Ad red text):
public static $definition = array(
'table' => 'address',
'primary' => 'id_address',
'fields' => array(
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_manufacturer' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_supplier' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_warehouse' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId', 'copy_post' => false),
'id_country' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
'id_state' => array('type' => self::TYPE_INT, 'validate' => 'isNullOrUnsignedId'),
'alias' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
'company' => array('type' => self::TYPE_STRING, 'validate' => 'isGenericName', 'size' => 64),
'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isNameWithDigits', 'required' => true, 'size' => 32),
'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'required' => true, 'size' => 32),

and save the file.

I think that's it. try to play with it a little (edit customer one more time after registration etc. as I didn't do that)

pascal

Link to comment
Share on other sites

  • 4 months later...
  • 4 weeks later...

Hi Pascal,

With the recent modification, I learned that it has somehow affected some buttons in my backend statistics part (as shown in the attached picture). Whenever I hit the button for the statistic, it shows errors, and another Prestashop [spam-filter] has found that it may be because of the modification in validity.php file:

 

"public static function isNameWithDigits($name)"

 

Will you be able to help further?

Thanks

Ian

post-477592-0-63318100-1391242176_thumb.png
Link to comment
Share on other sites

As the Error mentions on first line, it seems that the Validation function "isName" cannot be found. Did you make any modifications to the file? Maybe you forgot a } or so, which then messes up the functions after that? Just a wild guess...

 

Can you otherwise show me the change/addition you made or add the full Validate.php file so I can have a look? (please mention PrestaShop version)

 

pascal.

Link to comment
Share on other sites

Ian,

On second thoughts....

 

can it be that you didn't copy the isName function, but directly modified that function itself to function isNameWithDigits? Then you don't have any isName function any more, giving this error....

 

Let me know,

 

pascal.

Link to comment
Share on other sites

  • 8 years later...

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...