Jump to content

[Solved]How to force registration of the firstname in uppercase in the database?


leeloo

Recommended Posts

When a customer signs up, his lastname is recorded in the table customers and addresses in uppercase.

The firstname is written such that the client has entered.


Then in my authentification.tpl, i put a style in the input tag

 
input onkeyup="$('#firstname').val(this.value);" type="text" class="text" style="text-transform: uppercase;" id="customer_firstname" name="customer_firstname" value="{if isset($smarty.post.customer_firstname)}{$smarty.post.customer_firstname}{/if}" />


It's work but not in database.
How to force registration of the firstname in uppercase in the database ?

I voluntarily removed the opening tag < because it does not go to the forum

Link to comment
Share on other sites

  • 3 weeks later...

In "classes/Customer.php" ...

Find:

        $fields['firstname'] = pSQL($this->firstname);



Replace with:

        $fields['firstname'] = pSQL(Tools::strtoupper($this->firstname));




This coverts all characters to uppercase before adding it to the database :)

You can also apply this modification to "classes/Address.php" so the first name of the address is formatted the same.

Link to comment
Share on other sites

  • 8 months later...

I'm trying to do the same thing but having only the first letter uppercase of each word, I tried the ucwords function but no luck, strtoupper works but ucwords not.

 

Any idea? Many customers write everything in lowercase but I'd like my database and invoice tidy.

Thanks

Link to comment
Share on other sites

  • 2 months later...

I even tried with "ucfirst" function and works correctly but only the first word of the string and not each word of the string like "ucwords" function should do.

 

They should be all valid php functions, any idea why all works exempt the one I need?

 

http://www.php.net/m....strtoupper.php

http://www.php.net/m...ion.ucfirst.php

http://php.net/manua...ion.ucwords.php

 

WIth ucwords I get this: Fatal error: Call to undefined method Tools::ucwords() in .../classes/Customer.php on line 127

Link to comment
Share on other sites

When using ucwords you first need to make all the letters to lower first. ucwords only do the change to the first letter in each word so if the rest already are upper they will stay upper.

 

$test = "hELLO";



ucwords(strtolower($test));

// This will make it to Hello

Link to comment
Share on other sites

That would make sense but the problem is that that while other function like ucfirst or strtoupper are recognized by the system and works correctly, the function ucwords is not even recognized at all no matter how I configure it. Strange thing as all three seems valid PHP tools.

 

$fields['firstname'] = pSQL(Tools::strtoupper($this->firstname)); WORKS

 

$fields['firstname'] = pSQL(Tools::ucfirst($this->firstname)); WORKS

 

$fields['firstname'] = pSQL(Tools::ucwords($this->firstname)); FATAL ERROR*

 

 

*Fatal error: Call to undefined method Tools::ucwords() in .../classes/Customer.php on line 127

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 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...