Page 1 of 1

Customer Name Validation Makes No Sense

Posted: Wed Mar 05, 2008 3:00 pm
by bruce
This is a heads up on a problem that just occurred for me.

A customer named Li was unable to purchase an item on line because the customer name validation insists on a minimum of 3 characters for first name and last name. This validation should be removed.

The files that need changing to fix this are:

\catalog\controller\account_address.php
\catalog\controller\account_edit.php
\catalog\controller\checkout_address.php
\catalog\controller\account_create.php

in the validate() function in each file, contains code that looks like

Code: Select all

    	if ((strlen($request->get('firstname', 'post')) < 3) || (strlen($request->get('firstname', 'post')) > 32)) {
      		$this->error['firstname'] = $language->get('error_firstname');
    	}

    	if ((strlen($request->get('lastname', 'post')) < 3) || (strlen($request->get('lastname', 'post')) > 32)) {
      		$this->error['lastname'] = $language->get('error_lastname');
    	}
which should be, instead

Code: Select all

    	if ((strlen($request->get('firstname', 'post')) > 32)) {
      		$this->error['firstname'] = $language->get('error_firstname');
    	}

    	if ((strlen($request->get('lastname', 'post')) > 32)) {
      		$this->error['lastname'] = $language->get('error_lastname');
    	}
You also have to change the error messages in the language files (english shown as example).

\catalog\language\english\controller\account_address.php
\catalog\language\english\controller\account_edit.php
\catalog\language\english\controller\checkout_address.php
\catalog\language\english\controller\account_create.php

to something like

Code: Select all

$_['error_firstname']  = '* First Name must be less than 33 characters!';
$_['error_lastname']   = '* Last Name must be less than 33 characters!';
Note also, the change to 33 here to make the displayed text line up with the test performed in the code.

I actually removed all of the minimums except for password.

Re: Customer Name Validation Makes No Sense

Posted: Fri Mar 07, 2008 2:26 am
by JNeuhoff
I think the same is true for some other fields, e.g. a product description or product model should be allowed as empty fields, too.

Re: Customer Name Validation Makes No Sense

Posted: Thu Apr 24, 2008 3:10 am
by jocroft
Hi all,

In the process of trawling through all the forum threads to see all the recommended code changes etc. to make my opencart shop run as smooth as possible.

I see a lot of you guys contribute a lot and want to thank you for the time you've saved me.

On this topic though could you not just have changed the restriction to:

if ((strlen($request->get('firstname', 'post')) get('firstname', 'post')) > 32)) {
      $this->error['firstname'] = $language->get('error_firstname');
    }

    if ((strlen($request->get('lastname', 'post')) get('lastname', 'post')) > 32)) {
      $this->error['lastname'] = $language->get('error_lastname');
    }


so as to ensure than you get at least a first initial and a last name of at least two characters.

Would have thought that would be easier to change but I'm not sure if I'm missing something.

Re: Customer Name Validation Makes No Sense

Posted: Thu Apr 24, 2008 9:07 pm
by anmp3r
So in order to get rid of the user requirements such as address, could you just delete the code

Code: Select all

 address_1 = '?', address_2 = '?', postcode = '?', city = '?', zone_id = '?', country_id = '?'"
from

Code: Select all

if (($request->isPost()) && ($this->validateForm())) {

      		$sql = "insert into address set customer_id = '?', company = '?', firstname = '?', lastname = '?', address_1 = '?', address_2 = '?', postcode = '?', city = '?', zone_id = '?', country_id = '?'";
in each and every instance of each of those above files???

thanks! :)

Re: Customer Name Validation Makes No Sense

Posted: Fri Apr 25, 2008 11:03 am
by bruce
You don't need to change the sql or it's preparation, only the code in the validate function in the files listed, to perform the validation that you want for your shop.

Re: Customer Name Validation Makes No Sense

Posted: Fri Apr 25, 2008 4:22 pm
by anmp3r
ah right, so its just the

Code: Select all

if ((strlen($request->get('address_1', 'post')) < 3) || (strlen($request->get('address_1', 'post')) > 64)) {

      		$this->error['address_1'] = $language->get('error_address_1');

    	}



    	if ((strlen($request->get('city', 'post')) < 3) || (strlen($request->get('city', 'post')) > 32)) {

      		$this->error['city'] = $language->get('error_city');

    	}
bit i would change???

should i just delete it if i dont require users to enter info or should i change it somehow??

Thankyou!!! :)

Re: Customer Name Validation Makes No Sense

Posted: Fri Apr 25, 2008 5:04 pm
by bruce
Yes, that is what you can change.

strlen($request->get('city', 'post')) get('city', 'post')) > 32)
means...
If the user enters less than 3 characters OR The user enters more than 32 characters
then validation fails and an error message is displayed (from the appropriate language file)

The blue part makes the input of city compulsory but the 3 could be changed to a 1 if you want them to enter something but were prepared to accept anything.

The red part protects the program from runtime errors as the maximum number of characters for city in the database is 32. You should leave these tests in place.

Hence, to make city no longer compulsory but still protect the store from input values that are too long, you would use

Code: Select all

if (strlen($request->get('city', 'post')) > 32) 
{
    $this->error['city'] = $language->get('error_city');
}

Re: Customer Name Validation Makes No Sense

Posted: Fri Apr 25, 2008 5:26 pm
by anmp3r
thankyou sooooo much!!!! i was a bit confused before but now i understand!!!! :D

ur an awesome teacher!
:D

one last thing....  how do i get rid of those little red astrixs next to the text box's showing that they are compulsory?
thanks!

Re: Customer Name Validation Makes No Sense

Posted: Fri Apr 25, 2008 10:59 pm
by anmp3r
its ok, i just figured it out...
in file: /catalog/template/default/content/account_create.tpl

just take the astrixs out of

Code: Select all

          <td><span class="required">*</span> <?php echo $entry_address_1; ?></td>
          <td><input type="text" name="address_1" value="<?php echo $address_1; ?>" />
            <?php if ($error_address_1) { ?>
            <span class="error"><?php echo $error_address_1; ?></span>
            <?php } ?></td>
and

Code: Select all

          <td><span class="required">*</span> <?php echo $entry_telephone; ?></td>

          <td><input type="text" name="telephone" value="<?php echo $telephone; ?>" />

            <?php if ($error_telephone) { ?>

            <span class="error"><?php echo $error_telephone; ?></span>

            <?php } ?></td>
etc


:)

Re: Customer Name Validation Makes No Sense

Posted: Sat Apr 26, 2008 10:49 am
by bruce
now you are in to it... well done

Re: Customer Name Validation Makes No Sense

Posted: Sat Apr 26, 2008 3:32 pm
by anmp3r
hehe thanks mate!
;D

Re: Customer Name Validation Makes No Sense

Posted: Tue Nov 11, 2008 9:04 am
by nextgenxx
This is a good post for opencart, Can this be put in the next release? Everyone who uses open cart should update their files.

Re: Customer Name Validation Makes No Sense

Posted: Tue Nov 11, 2008 9:15 am
by Qphoria
better still.. just set the tpl field for maxlength of 32 and do no max length error validation :)