WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Bakery Shop => Topic started by: svsanchez on November 26, 2013, 11:19:03 PM

Title: Bakery Second Address line field
Post by: svsanchez on November 26, 2013, 11:19:03 PM
Hello community, I am running into trouble with the address field as there is only one text field. I would like to know if it's possible to add a second address line or to modify the text field into a text area? I tried using the custom fields but it seems it's not possible to use them for the address?

Thank you!
Title: Re: Bakery Second Address line field
Post by: jacobi22 on November 27, 2013, 09:46:21 AM
i think, custom fields are only for the product page, not for the form
its no problem, to change the second line to a textarea, but you have to change the control check for this field too (only 50 chars for this field)
Title: Re: Bakery Second Address line field
Post by: svsanchez on November 27, 2013, 03:17:14 PM
Hello Jacobi, thank you for your reply. Where can I change the field type and the control check?
Title: Re: Bakery Second Address line field
Post by: jacobi22 on November 27, 2013, 05:48:38 PM
i think, bakery 1,6??

i talk a little too fast  :oops: :lol:

bakery goes into a loop for the form, so it can be flexible or dynamic in the form, so its not possible to change only one input field only

i test this way: i use textarea's for all input areas, textareas has a standard min-height from 3 rows,(if you not define a seperat height) so i change the area-height with css. i put p{NAME} into the class, so that you have CSS-classes like pcust_email, pcust_confirm_email etc
(watch the p before the field btw class names!)
Look into the source code from the Form for the correct textarea names

for Vers 1.60 only!
File: modules/bakery/templates/form/form.htm // line 23 - 28
original code
Code: [Select]
<!-- BEGIN cust_textfields_block -->
<tr id="{TR_ID}">
        <td class ="mod_bakery_form_label_f">{LABEL}</td>
        <td><input type="text" class="{CSS_ERROR_CLASS}mod_bakery_form_input_f" name="{NAME}" value="{VALUE}" maxlength="{MAXLENGHT}" /></td>
</tr>
<!-- END cust_textfields_block -->

new code
Code: [Select]
<!-- BEGIN cust_textfields_block -->
<tr id="{TR_ID}">
        <td class ="mod_bakery_form_label_f">{LABEL}</td>
        <td><textarea type="text" class="{CSS_ERROR_CLASS}mod_bakery_form_input_f p{NAME}" name="{NAME}" value="" maxlength="{MAXLENGHT}">{VALUE}</textarea></td>
</tr>
<!-- END cust_textfields_block -->

in the frontend.css i build new classes like  pcust_email, pcust_confirm_email etc

with these entry for a smaler input area / input field - in the eample for all input fields but not for the last name

Code: [Select]
.pcust_email, .pcust_confirm_email, .pcust_first_name, .pcust_street, .pcust_zip, .pcust_city {height:14px;}
if you want you can set the text on the left side from the textarea to the top in this row with this entry in the frontend.css
Code: [Select]
tr#cust_last_name_text {
        vertical-align:top;
}


bakery 1.60 check the form in the view.php , nearly line 474

here the original code  for the field "last name"
Code: [Select]
if (strpos($field, 'last_name') !== false) {
                                if (!preg_match('#^[A-Za-z'.$add_chars.' -]{1,50}$#', $value)) {
                                        $error_bg[] = $field;
                                        $errors[] = htmlspecialchars($value, ENT_QUOTES).' '.$MOD_BAKERY['ERR_INVAL_NAME'];
                                }
                        }

change the 50 in line 2 from this code here with your max chars for this textarea
maybe from {1,50} to {1,300}

then go to view_form.php to this lines 147 - 190 and set the max lenght for your field (4 x)
in my eample i will have the field "last name" as a textarea with 300 chars as max, so i need to change this part here
from "cust_last_name" => "50", to "cust_last_name" => "300", in line 172, 176, 184 and line 188

here the original code from the view_form.php without these changes

Code: [Select]
// Make array for the customer address form with state field
if ($setting_state_field == "show") {
        if ($setting_zip_location == "end") {
                // Show zip at the end of address
                $cust_info = array("cust_email" => $MOD_BAKERY['TXT_CUST_EMAIL'], "cust_confirm_email" => $MOD_BAKERY['TXT_CUST_CONFIRM_EMAIL'], "cust_first_name" => $MOD_BAKERY['TXT_CUST_FIRST_NAME'], "cust_last_name" => $MOD_BAKERY['TXT_CUST_LAST_NAME'], "cust_tax_no" => $MOD_BAKERY['TXT_CUST_TAX_NO'], "cust_street" => $MOD_BAKERY['TXT_CUST_ADDRESS'], "cust_city" => $MOD_BAKERY['TXT_CUST_CITY'], "cust_state" => $MOD_BAKERY['TXT_CUST_STATE'], "cust_zip" => $MOD_BAKERY['TXT_CUST_ZIP'], "cust_country" => $MOD_BAKERY['TXT_CUST_COUNTRY'], "cust_phone" => $MOD_BAKERY['TXT_CUST_PHONE']);
                $length = array("cust_email" => "50", "cust_confirm_email" => "50", "cust_first_name" => "50", "cust_last_name" => "50", "cust_tax_no" => "20", "cust_street" => "50", "cust_zip" => "10", "cust_city" => "50", "cust_state" => "50", "cust_phone" => "20");
        } else {
                // Show zip inside of address
                $cust_info = array("cust_email" => $MOD_BAKERY['TXT_CUST_EMAIL'], "cust_confirm_email" => $MOD_BAKERY['TXT_CUST_CONFIRM_EMAIL'], "cust_first_name" => $MOD_BAKERY['TXT_CUST_FIRST_NAME'], "cust_last_name" => $MOD_BAKERY['TXT_CUST_LAST_NAME'], "cust_tax_no" => $MOD_BAKERY['TXT_CUST_TAX_NO'], "cust_street" => $MOD_BAKERY['TXT_CUST_ADDRESS'], "cust_zip" => $MOD_BAKERY['TXT_CUST_ZIP'], "cust_city" => $MOD_BAKERY['TXT_CUST_CITY'], "cust_state" => $MOD_BAKERY['TXT_CUST_STATE'], "cust_country" => $MOD_BAKERY['TXT_CUST_COUNTRY'], "cust_phone" => $MOD_BAKERY['TXT_CUST_PHONE']);
                $length = array("cust_email" => "50", "cust_confirm_email" => "50", "cust_first_name" => "50", "cust_last_name" => "50", "cust_tax_no" => "20", "cust_street" => "50", "cust_zip" => "10", "cust_city" => "50", "cust_state" => "50", "cust_phone" => "20");
        }
}
// Make array for the customer address form w/o state field
else {
        if ($setting_zip_location == "end") {
                // Show zip at the end of address
                $cust_info = array("cust_email" => $MOD_BAKERY['TXT_CUST_EMAIL'], "cust_confirm_email" => $MOD_BAKERY['TXT_CUST_CONFIRM_EMAIL'], "cust_first_name" => $MOD_BAKERY['TXT_CUST_FIRST_NAME'], "cust_last_name" => $MOD_BAKERY['TXT_CUST_LAST_NAME'], "cust_tax_no" => $MOD_BAKERY['TXT_CUST_TAX_NO'], "cust_street" => $MOD_BAKERY['TXT_CUST_ADDRESS'], "cust_city" => $MOD_BAKERY['TXT_CUST_CITY'], "cust_zip" => $MOD_BAKERY['TXT_CUST_ZIP'], "cust_country" => $MOD_BAKERY['TXT_CUST_COUNTRY'], "cust_phone" => $MOD_BAKERY['TXT_CUST_PHONE']);
                $length = array("cust_email" => "50", "cust_confirm_email" => "50", "cust_first_name" => "50", "cust_last_name" => "50", "cust_tax_no" => "20", "cust_street" => "50", "cust_zip" => "10", "cust_city" => "50", "cust_phone" => "20");
        } else {
                // Show zip inside of address
                $cust_info = array("cust_email" => $MOD_BAKERY['TXT_CUST_EMAIL'], "cust_confirm_email" => $MOD_BAKERY['TXT_CUST_CONFIRM_EMAIL'], "cust_first_name" => $MOD_BAKERY['TXT_CUST_FIRST_NAME'], "cust_last_name" => $MOD_BAKERY['TXT_CUST_LAST_NAME'], "cust_tax_no" => $MOD_BAKERY['TXT_CUST_TAX_NO'], "cust_street" => $MOD_BAKERY['TXT_CUST_ADDRESS'], "cust_zip" => $MOD_BAKERY['TXT_CUST_ZIP'], "cust_city" => $MOD_BAKERY['TXT_CUST_CITY'], "cust_country" => $MOD_BAKERY['TXT_CUST_COUNTRY'], "cust_phone" => $MOD_BAKERY['TXT_CUST_PHONE']);
                $length = array("cust_email" => "50", "cust_confirm_email" => "50", "cust_first_name" => "50", "cust_last_name" => "50", "cust_tax_no" => "20", "cust_street" => "50", "cust_zip" => "10", "cust_city" => "50", "cust_phone" => "20");
        }
}

after all theses changes you have to restart the view.php (if the shop site is open in the browser) and maybe clear the browser cache for the new max lengt in the textarea, otherwise it comes a error message, that the input is not the correct entry for this field.

P.S.: everything here is testet with bakery 1.60 in a wb 2.8.3 on a server with PHP 5.5.3

another p.s.:  remember, that the long entry goes to other parts from bakery, so to the invoices, the mails, the payment methodes, so you have to check the design and output for this long text input in other pages or documents
Title: Re: Bakery Second Address line field
Post by: svsanchez on November 28, 2013, 10:49:46 PM
Hmmm, thank you Jacobi, looks a little complicated but I guess I will be able to do this with your step by step instructions. I will post here my results :)
Title: Re: Bakery Second Address line field
Post by: jacobi22 on November 28, 2013, 11:01:12 PM
Quote
I will post here my results Smiley

i hope so  ;-)
Title: Re: Bakery Second Address line field
Post by: svsanchez on November 29, 2013, 01:30:58 AM
For clarification purposes in case other people are interested in this modification, this is to allow a bigger ADDRESS FIELD (not last name field). Simply do what Jacobi22 instructs here but when he mentions last_name you have to apply the changes to the address field (STREET)  :wink:

Ok, I almost did it but I am running into the 2 following problems:

1) Since all fields were converted to small textareas, they have the sizing box option activated, which doesn't look ok and can lead to confusion with customers trying to add more text into the fields. I tried adding box-sizing:none; to the frontend.css but it didn't work. How can I get rid of the box sizing on those fields?

2) My address box now looks nice with the default 3 rows for entering the bigger address for those customers who need it, BUT Bakery won't accept any address if I hit the "ENTER" key. So if I add something like:

BOX 695 [ENTER]
1869 NW 97th Ave

It won't accept the address. I googled for the regex character for the [ENTER] char and couldn't find anything conclusive, so I tried adding \r to the $MOD_BAKERY['ADD_REGEXP_CHARS'] = 'áéíóúñÑ\r';

Unfortunately the \r didn't work so I guess I need something else there.
Title: Re: Bakery Second Address line field
Post by: svsanchez on December 02, 2013, 06:04:48 PM
Hello, could someone please tell me if it's possible to fix the above mentioned problems, as the solution provided by Jacobi won't work because Bakery won't accept the address when the customer hits the [enter] key.

Thank you
Title: Re: Bakery Second Address line field
Post by: jacobi22 on December 02, 2013, 07:10:43 PM
Quote
1) Since all fields were converted to small textareas, they have the sizing box option activated, which doesn't look ok and can lead to confusion with customers trying to add more text into the fields. I tried adding box-sizing:none; to the frontend.css but it didn't work. How can I get rid of the box sizing on those fields?

resize:none is the solution

for my example i use it here in the frontend.css (see the example in the last posting)
Code: [Select]
.pcust_email, .pcust_confirm_email, .pcust_first_name, .pcust_last_name, .pcust_zip, .pcust_city {height:16px;resize: none;}
Quote
Hello, could someone please tell me if it's possible to fix the above mentioned problems, as the solution provided by Jacobi won't work because Bakery won't accept the address when the customer hits the [enter] key.

use \s in preg_match, its for whitespaces and include the break or "new row"
example (but it works for me without problems)

view.php // line 498
Code: [Select]
if (strpos($field, 'street') !== false) {
                                if (!preg_match('#^[\sA-Za-z0-9'.$add_chars.' +&-]{1,500}$#', $value)) {
                                        $error_bg[] = $field;
                                        $errors[] = htmlspecialchars($value, ENT_QUOTES).' '.$MOD_BAKERY['ERR_INVAL_STREET'];
                                }
                        }

then go to this code in line 564 ff and change it from
original
Code: [Select]
// If all fields correct, write into db
        foreach ($_POST as $field => $value) {
                if ($field != 'summary' && $field != 'cust_confirm_email') {
                        $field = $admin->add_slashes(strip_tags($field));
                        $value = $admin->add_slashes(strip_tags($value));
                        $updates[] = "$field = '$value'";
                }
        }

to
Code: [Select]
// If all fields correct, write into db
        foreach ($_POST as $field => $value) {
                if ($field != 'summary' && $field != 'cust_confirm_email') {
                        $field = $admin->add_slashes(strip_tags($field));
                        $value = $admin->add_slashes(strip_tags($value));
                        $value = nl2br($value);
                        $updates[] = "$field = '$value'";
                }
        }


then go to view_summary.php at line 185 to this code here
Code: [Select]
// Join customer first and last name
$cust_name = $cust_first_name." ".$cust_last_name;


and change it to
Code: [Select]
// Join customer first and last name
$cust_name = $cust_first_name." ".$cust_last_name;
$cust_street = nl2br($cust_street);

for your special char problem...
maybe it helps, if you use this chars direct in the preg_match-code, like this

view.php // line 498
Code: [Select]
if (strpos($field, 'street') !== false) {
                                if (!preg_match('#^[\sA-Za-z0-9'.$add_chars.' áéíóúñÑ+&-]{1,500}$#', $value)) {
                                        $error_bg[] = $field;
                                        $errors[] = htmlspecialchars($value, ENT_QUOTES).' '.$MOD_BAKERY['ERR_INVAL_STREET'];
                                }
                        }
Title: Re: Bakery Second Address line field
Post by: svsanchez on December 03, 2013, 12:28:14 AM
Thank you Jacobi! I'm almost finished, the only problem now is that I can add the second line to the customer's address BUT NOT to the SHIPPING address. I tried the following but I only made my shipping address fields disappear:

1) In frontend.css I added the other fields, so now I have:

Code: [Select]
.pcust_email, .pcust_confirm_email, .pcust_first_name, .pcust_last_name, .pcust_zip, .pcust_city, .pcust_phone, .pship_first_name, .pship_last_name, .pship_city, .pship_zip {height:16px; resize:none;}

2) Then in form.htm I changed the ship textfield blocks so it now looks like this:

Code: [Select]
<!-- BEGIN ship_textfields_block
<tr id="{TR_ID}">
<td class ="mod_bakery_form_label_f">{LABEL}</td>
<td><textarea type="text" class="{CSS_ERROR_CLASS}mod_bakery_form_input_f p{NAME}" name="{NAME}" value="" maxlength="{MAXLENGHT}">{VALUE}</textarea></td>
</tr>
END cust_textfields_block -->

I just tried repeating what you told me for the shipping address but it wasn't as easy as I hoped, what did I do wrong?
Title: Re: Bakery Second Address line field
Post by: jacobi22 on December 03, 2013, 02:38:32 PM

2) Then in form.htm I changed the ship textfield blocks so it now looks like this:

Code: [Select]
<!-- BEGIN ship_textfields_block
<tr id="{TR_ID}">
<td class ="mod_bakery_form_label_f">{LABEL}</td>
<td><textarea type="text" class="{CSS_ERROR_CLASS}mod_bakery_form_input_f p{NAME}" name="{NAME}" value="" maxlength="{MAXLENGHT}">{VALUE}</textarea></td>
</tr>
END cust_textfields_block -->
I just tried repeating what you told me for the shipping address but it wasn't as easy as I hoped, what did I do wrong?

thats wrong!!!
a comment in HTML starts with <!--, the end is  -->, i'm missing the end in your first line and the start in your last line, so the whole code is a comment in this moment
It's also important, that you not change the comment text - there are the limiter for the display - it doesnt work, if you have the text BEGIN ship_textfields_blo ck at the start and END cust_textfields_block at the end from the same block
please check your code about this or copy the code from here

Step 1
here the correct code with textareas for the shipping fields
(File: modules/bakery/templates/form/form.htm // line 81 - 86
Code: [Select]
<!-- BEGIN ship_textfields_block -->
<tr id="{TR_ID}">
        <td class ="mod_bakery_form_label_f">{LABEL}</td>
        <td><textarea type="text" class="{CSS_ERROR_CLASS}mod_bakery_form_input_f p{NAME}" name="{NAME}" value="" maxlength="{MAXLENGHT}">{VALUE}</textarea></td>
</tr>
<!-- END ship_textfields_block -->

Step 2 - change the CSS - is correct in your code

Step 3
change the maxlenght from 50 to 500 in view_form.php in the lines between 280 and 302 (4x)
OLD : "ship_street" => "50"
NEW  "ship_street" => "500"

Step 4
go to view_summary.php // Line 239 to this code
Code: [Select]
// Join customer first and last name
        $ship_name = $ship_first_name." ".$ship_last_name;

and change it to
Code: [Select]
// Join customer first and last name
        $ship_name = $ship_first_name." ".$ship_last_name;
        $ship_street = nl2br($ship_street);

thats all (for me). If you have some errors, please post the messages or discribe the error
i dont test the mail messages, but i think, everything is okay

one Question... (here in germany we use an other adress system)

you write, you need a street field for Entrys like this
BOX 695 [ENTER]
1869 NW 97th Ave

i think
Box 695 is a post box
1869 NW is the postal or zip-code and the City
97th Ave is the Street
correct?
what are you doing with the fields for the zip-Code and the city?




Title: Re: Bakery Second Address line field
Post by: svsanchez on December 04, 2013, 01:34:56 AM
Hello Jacobi!

Your solution worked great! There's only 2 minor things that I would like to fix with it:

1) When I hit the [enter] key in the address field, the email that is sent to the shop owner shows a <br />. I can tell the customer to live with it but if it's something easily fixable it would be great to remove it :)

2) Some addresses in Guatemala use the quotation marks and comma, for example we have something like 1st Street "A", 1st Street "B" when they are intermediate streets. Right now when I include a quotation mark in the address Bakery won't accept it so there's another special char that I have to add to the regexp but don't know how to represent the quotation marks and the comma (,) characters!

Regarding your questio, the example address I sent you was just to try to explain what I was trying to achieve. But in Guatemala we use something like this:

20 Calle 16-03
Colonia Granai III
Zona 11
Guatemala, Guatemala

The first line tells you the address is located in the 20th street between the 16th and 17th streets, 3 meters from the corner of the 16th avenue. Blocks here are 100 meters wide, so having an address like 20 calle 16-50 would tell you the house is located in the 20th street, between the 16th and 17th avenues, right in the middle (50 meters from the corner of the 16th).

The second line is not always used, but when the address is inside a condominum or an appartment building, you put there the name of the condominum or the building name (like for example World Trade Center was the name of the building)

The third line is like the zip code, but here we use something called Zones which have 2 digits. Each zone also has a postal code equivalent but almost nobody uses it, only the Zone.

And finally you have the City name.

So I am using both the zip and city fields but changed the zip field to allow only 2 digits (you also helped me on this one  :-) )

Title: Re: Bakery Second Address line field
Post by: svsanchez on December 05, 2013, 06:13:43 AM
Could someone please tell me how to tell Bakery to accept the quotes and comma characters in the address field? I have searched and googled this but haven't been able to get it to work.
Title: Re: Bakery Second Address line field
Post by: jacobi22 on December 05, 2013, 01:19:54 PM
for the moment i use this regex in the preg_match for the field "street", it means

\s"\,\$\&\A-Za-z0-9'.$add_chars.' áéíóúñÑ+-]{1,500}
allowed:
- whitespaces (Space, tab, or newline)
- "
- ,
- &
- Chars from A-Z and a-z and 0-9
- $addchars (the special chars from the EN.php)
- your special chars áéíóúñÑ
- + and -
if you need more chars, try it at the begin from the regex nearly s\"\, use the char and a \

Code: [Select]
if (strpos($field, 'street') !== false) {
                                if (!preg_match('#^[\s"\,\$\&\A-Za-z0-9'.$add_chars.' áéíóúñÑ+-]{1,500}$#', $value)) {
                                        $error_bg[] = $field;
                                        $errors[] = htmlspecialchars($value, ENT_QUOTES).' '.$MOD_BAKERY['ERR_INVAL_STREET'];
                                }
                        }

the problem with the special chars is, if you go 1 step back, maybe for repairing your adress datas, you have a entry in the textfield like this
Reuden &quot;Nord&quot;
its not a error, but i looks bad for the customer

another problem - i found a way for the <br /> in the mails, but the design is not the best. normally you have a little space in every adress line before the adress starts, like
Adress
          20 Calle 16-03
          Colonia Granai III
          Zona 11
          Guatemala, Guatemala

the adress in the database is a formated text, so i can only take the <br> from this text and put a \n on this place, but after a \n the next line starts at the begin from the next line, like
Adress
          20 Calle 16-03
Colonia Granai III
          Zona 11
          Guatemala, Guatemala

my solution is this new lines in the view_confirmation.p hp
Code: [Select]
$cust_address = str_replace("<br>", "\r\n", $cust_address);
$cust_address = str_replace("<br />", "\r\n", $cust_address);
$ship_address = str_replace("<br>", "\r\n", $ship_address);
$ship_address = str_replace("<br />", "\r\n", $ship_address);

in this block nearly line 122
Code: [Select]
if ($customer['invoice'] != '') {
                                        // Convert string to array
                                        $invoice = stripslashes($customer['invoice']);
                                        $invoice_array = explode('&&&&&', $invoice);

                                        // Email vars to replace placeholders in the email body
                                        $setting_shop_name = $invoice_array[1];
                                        $bank_account      = $invoice_array[2];
                                        $cust_name         = $invoice_array[3];
                                        $cust_email        = $invoice_array[7];
                                        $shop_email        = $invoice_array[10];
                                        $address           = $invoice_array[11];
                                        $cust_address      = $invoice_array[12];
                                        $ship_address      = $invoice_array[13];
                                        $item_list         = $invoice_array[14];
                                        $cust_tax_no       = $invoice_array[15];
                                }

copy the 4 new line to the end before the }

maybe it helps, if you set 10 or more space's in the replace-code, like

Code: [Select]
$cust_address = str_replace("<br>", "          \r\n", $cust_address);
but i will look for a better way and i search for the place, where the adress has been formatet

a last question: you have test the bakery Vers 1.7, have you found there the same problems with your special chars?

Bakery 1.7 works with a config.php, there are defined the $addchars
bakery 1.6 works with special chars defined in every language file

i think, you use only the english language file, please check, if you found a full entry in your EN.php
normally its empty in the EN.php
Code: [Select]
$MOD_BAKERY['ADD_REGEXP_CHARS'] = '';
if so in your file, replace it with
Code: [Select]
$MOD_BAKERY['ADD_REGEXP_CHARS'] = 'ÁÀÂÃÄÅáà âãäåÆæÇçČčÐðÉÈÊËéèêëÍÌÎÏíìîïÑñÓÒÔÕÖØóòôõöøŒœÞþÚÙÛÜúùûüŠšßÝŸýÿŽžÂ';
Title: Re: Bakery Second Address line field
Post by: svsanchez on December 05, 2013, 04:34:45 PM
Hello Jacobi

Thank you so much for your help and teaching me how to add new special characters, I was able to add the dot character which is misssing in your example by adding \.

I'm not sure if it's an error in your example you have \s"\,\$\&\A-Za-z0-9'.$add_chars.' áéíóúñÑ+-]{1,500} so it seems like the \ is missing in front of the " but maybe \s" would also work. I changed it to \s\"\, and it worked on my test :)

Regarding the </br> it's a good solution!

As for Bakery 1.7 I have stayed away from it since it doesn't allow to "SKIP CHECKOUT IF ONLY ONE PAYMENT METHOD IS SELECTED", don't really know why the developer removed that useful feature. You see, there are many countries that don't have too many payment options and in many cases companies only want to show their products without prices but only want to allow customers to ask them for a quote, so bakery 1.6 allows me to do this pretty easily while 1.7 makes it too confusing.