Jump to content

Capitalize First Letters of address input fields, and submit to database


Recommended Posts

Hi All,

Is there a way to capitalize and submit the first letters of the name and address input fields on registration? for example;

john doe smith
main street 123
1234 aa town

John Doe Smith
Main Street 123
1234 AA Town

I tried css {text-transform:capitalize;}, unfortunately this only change the user values entered, it doesn't submit and store the capitalized text into the database.

Thanks

Link to comment
Share on other sites

Hi All,

 

Is there a way to capitalize and submit the first letters of the name and address input fields on registration? for example;

 

john doe smith

main street 123

1234 aa town

 

John Doe Smith

Main Street 123

1234 AA Town

 

I tried css {text-transform:capitalize;}, unfortunately this only change the user values entered, it doesn't submit and store the capitalized text into the database.

 

Thanks

 

There are three steps. Add these lines of codes in following files:

 

 

Step 1:yourprojectfolder/controllers/front/addressController.php under line number 126

 

        // Capitalize the first name

        $address->firstname = ucwords(Tools::getValue('firstname'));

        

        // Capitalize the first name

        $address->lastname = ucwords(Tools::getValue('lastname'));

        

        // Capitalize the address fields

        $address->address1 = ucwords(Tools::getValue('address1'));

        $address->address2 = ucwords(Tools::getValue('address2'));

 

Step 2:yourprojectfolder/classes/controller/AdminController.php under line number 2309

if ($this->list_id == 'customer' || $this->list_id == 'address')

                foreach ($this->_list as $key => $record) {

                    $this->_list[$key]['firstname'] = ucwords($record['firstname']);

                    $this->_list[$key]['lastname'] = ucwords($record['lastname']);

                    $this->_list[$key]['address1'] = ucwords($record['address1']);

                    $this->_list[$key]['address1'] = ucwords($record['address1']);

            }

 

Step 3: Add this css code in yourprojectfolder/youradminfolder/beheer/themes/default/css/admin.css

 

form#address_form input#firstname, form#address_form input#lastname, form#customer_form input#firstname, form#customer_form input#lastname, form#address_form input#address1, form#address_form input#address2 {

    text-transform:capitalize;

}

 

 

 

Link to comment
Share on other sites

  • 1 month later...
  • 6 months later...
  • 8 months later...

Fix for PS 1.6

 

Go to yourprojectfolder/classes/Address.php

 

Search for "public function add($autodate = true, $null_values = false)" on line 169.

Replace :
 

public function add($autodate = true, $null_values = false)
{
    if (!parent::add($autodate, $null_values)) {
        return false;
    }

    if (Validate::isUnsignedId($this->id_customer)) {
        Customer::resetAddressCache($this->id_customer, $this->id);
    }
    return true;
}

With:

public function add($autodate = true, $null_values = false)
{
  if (!parent::add($autodate, $null_values)) {
      return false;
  }
  
  // Capitalize the first name
  $this->firstname = ucfirst($this->firstname);
  
  // Capitalize the first name
  $this->lastname = ucfirst($this->lastname);
  
  // Capitalize the address fields
  $this->address1 = ucfirst($this->address1);
  $this->address2 = ucfirst($this->address2);
  
  if (Validate::isUnsignedId($this->id_customer)) {
      Customer::resetAddressCache($this->id_customer, $this->id);
  }
  return true;
}

Search for "public function update($null_values = false)" on line 181.

Replace :

 

public function update($null_values = false)
{
    // Empty related caches
    if (isset(self::$_idCountries[$this->id])) {
        unset(self::$_idCountries[$this->id]);
    }
    if (isset(self::$_idZones[$this->id])) {
        unset(self::$_idZones[$this->id]);
    }

    if (Validate::isUnsignedId($this->id_customer)) {
        Customer::resetAddressCache($this->id_customer, $this->id);
    }

    return parent::update($null_values);
}

With:

public function update($null_values = false)
{
  // Empty related caches
  if (isset(self::$_idCountries[$this->id])) {
      unset(self::$_idCountries[$this->id]);
  }
  if (isset(self::$_idZones[$this->id])) {
      unset(self::$_idZones[$this->id]);
  }
  
  // Capitalize the first name
  $this->firstname = ucfirst($this->firstname);
  
  // Capitalize the first name
  $this->lastname = ucfirst($this->lastname);
  
  // Capitalize the address fields
  $this->address1 = ucfirst($this->address1);
  $this->address2 = ucfirst($this->address2);
  
  if (Validate::isUnsignedId($this->id_customer)) {
      Customer::resetAddressCache($this->id_customer, $this->id);
  }

  return parent::update($null_values);
}

Instead of changing the PrestaShop core. You can also use the override option.

 

Create the file yourprojectfolder/override/classes/Address.php and insert this code and save the file:

<?php
/**
* Fix for capitalize and submit the first letters of the name and address input fields
*
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
*  @author Peter Visser <[email protected]>
*/

class Address extends AddressCore
{

  public function update($null_values = false)
  {
    // Empty related caches
    if (isset(self::$_idCountries[$this->id])) {
        unset(self::$_idCountries[$this->id]);
    }
    if (isset(self::$_idZones[$this->id])) {
        unset(self::$_idZones[$this->id]);
    }
    
    // Capitalize the first name
    $this->firstname = ucfirst($this->firstname);
    
    // Capitalize the first name
    $this->lastname = ucfirst($this->lastname);
    
    // Capitalize the address fields
    $this->address1 = ucfirst($this->address1);
    $this->address2 = ucfirst($this->address2);
    
    if (Validate::isUnsignedId($this->id_customer)) {
        Customer::resetAddressCache($this->id_customer, $this->id);
    }

    return parent::update($null_values);
  }
  
  public function add($autodate = true, $null_values = false)
  {
    if (!parent::add($autodate, $null_values)) {
        return false;
    }
    
    // Capitalize the first name
    $this->firstname = ucfirst($this->firstname);
    
    // Capitalize the first name
    $this->lastname = ucfirst($this->lastname);
    
    // Capitalize the address fields
    $this->address1 = ucfirst($this->address1);
    $this->address2 = ucfirst($this->address2);
    
    if (Validate::isUnsignedId($this->id_customer)) {
        Customer::resetAddressCache($this->id_customer, $this->id);
    }
    return true;
  }
}

After that reset your cache for overrides bij deleting yourprojectfolder/cache/class_index.php

 

That's it! Good luck

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Hi, I'm trying to do this in 1.5.4.1. However I want do to it in both the user data and the address.

 

The point is to make sure that always the first and lastname, all the address fields (company, address1, 2, city, dni, vat_number and postcode) have every first letter of every word in Upper Case and the rest in Lower Case.

 

I did this:

 

/controllers/front/AuthController.php
 
$customer->firstname = Tools::ucwords($customer->firstname);
$customer->lastname = Tools::ucwords($customer->lastname);
 
/controllers/front/IdentityController.php
 
$this->customer->firstname = Tools::ucwords($this->customer->firstname);
$this->customer->lastname = Tools::ucwords($this->customer->lastname);
 
 
However for /controllers/front/AddressController.php, only this worked for me:

        $address->firstname = Tools::ucwords(Tools::getValue('firstname'));

        $address->lastname = Tools::ucwords(Tools::getValue('lastname'));

        $address->address1 = Tools::ucwords(Tools::getValue('address1'));

        $address->address2 = Tools::ucwords(Tools::getValue('address2'));

        $address->company = Tools::ucwords(Tools::getValue('company'));

        $address->dni = Tools::ucwords(Tools::getValue('dni'));

        $address->city = Tools::ucwords(Tools::getValue('city'));

        $address->vat_number = Tools::ucwords(Tools::getValue('vat_number'));

        $postcode = Tools::ucwords(Tools::getValue('postcode'));

 

 

Note the change in postcode, otherwise it doesn't work. Why ? (I'm not a php programmer !)

 

Also, I did STEP 3, as indicated by kashifkhan112 but I'm not sure what that means, because the "input" screen still shows the lower case during the input ...

 

However, I'm not sure about WHERE (lines don't seem to match, so don't know what should be before and after line 2309) I need to do STEP 2 and what that is doing ...

 

I think is working because using a select in the mySQL I see the upper case in each first letter, even if I have input (lower case or upper case) and the rest is converted to lower case.

 

Thanks !

 

 

Link to comment
Share on other sites

  • 5 months later...
×
×
  • Create New...