Post by bruce » Wed Mar 05, 2008 3:00 pm

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.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by JNeuhoff » Fri Mar 07, 2008 2:26 am

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.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member
Online

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by jocroft » Thu Apr 24, 2008 3:10 am

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.

I know you think you understood what I said, but what you heard was not what I meant


New member

Posts

Joined
Thu Mar 13, 2008 9:03 pm
Location - England

Post by anmp3r » Thu Apr 24, 2008 9:07 pm

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! :)

visit my mobile phone store! ---> http://m-shop.guardhost.net


New member

Posts

Joined
Sun Apr 20, 2008 10:48 pm


Post by bruce » Fri Apr 25, 2008 11:03 am

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.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by anmp3r » Fri Apr 25, 2008 4:22 pm

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!!! :)

visit my mobile phone store! ---> http://m-shop.guardhost.net


New member

Posts

Joined
Sun Apr 20, 2008 10:48 pm


Post by bruce » Fri Apr 25, 2008 5:04 pm

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');
}

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by anmp3r » Fri Apr 25, 2008 5:26 pm

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!
Last edited by anmp3r on Fri Apr 25, 2008 6:12 pm, edited 1 time in total.

visit my mobile phone store! ---> http://m-shop.guardhost.net


New member

Posts

Joined
Sun Apr 20, 2008 10:48 pm


Post by anmp3r » Fri Apr 25, 2008 10:59 pm

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


:)

visit my mobile phone store! ---> http://m-shop.guardhost.net


New member

Posts

Joined
Sun Apr 20, 2008 10:48 pm


Post by bruce » Sat Apr 26, 2008 10:49 am

now you are in to it... well done

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by anmp3r » Sat Apr 26, 2008 3:32 pm

hehe thanks mate!
;D

visit my mobile phone store! ---> http://m-shop.guardhost.net


New member

Posts

Joined
Sun Apr 20, 2008 10:48 pm


Post by nextgenxx » Tue Nov 11, 2008 9:04 am

This is a good post for opencart, Can this be put in the next release? Everyone who uses open cart should update their files.

User avatar
New member

Posts

Joined
Tue Jul 15, 2008 1:13 am


Post by Qphoria » Tue Nov 11, 2008 9:15 am

better still.. just set the tpl field for maxlength of 32 and do no max length error validation :)

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 4 guests