View Single Post
  #82  
Old 06-18-2005, 06:58 AM
 
r.jones r.jones is offline
 

Newbie
  
Join Date: May 2005
Posts: 5
 

Default

This is a revision of the code I posted in this thread on May 18th, 2005. It addresses two problems with the original code:

1) An onBlur event isnБ─≥t executed under every circumstance (using the enter key instead of selecting the formБ─≥s submit button). So this has been removed and the data is now moved by the check_registerform_fields() function.

2) If the user has disabled javascript, the b_firstname and b_lastname fields remain empty the first time the form is submitted. This causes an error message that the user canБ─≥t correct because the fields are hidden. If the form is submitted again it will work because the fields contain firstname and lastname data that are now in the database from the first submission. So, now I only hide the fields when the javascript option is enabled. People that don't use javascript will have to do some extra typing.

Note: This still doesn't address the scenario of javascript being disabled and the user hasn't selected the Б─°If Javascript is disabled in your browser click hereБ─² option. They would still get an error message, but nothing would indicate what the problem is. Good enough for my purposes, but there is still room for improvement.

This is the code IБ─≥m currently using:

Step 1:

General Settings : User Profile options

Set "First Name" and "Last Name" to Active and Required.

Step 2:

Apply this patch, http://forum.x-cart.com/download.php?id=9 which allows the ship to names to be left blank. Shoppers will see a message: Shipping Address (leave empty if same as billing address). The patch changes only a few lines in two files. The "-" (minus sign) indicates the code that is removed, and the "+" (plus sign) indicates the code that replaces it.

Step 3:

Hide the billing names if javascript is enabled by changing main/register_billing_address.tpl starting at about line 28 from:

Code:
{if $default_fields.firstname.avail eq 'Y'} <TR> <TD align="right">{$lng.lbl_first_name}</TD> <TD>{if $default_fields.firstname.required eq 'Y'}<FONT class="Star">*</FONT>{else}{/if}</TD> <TD nowrap> <INPUT type="text" name="b_firstname" size="32" maxlength="32" value="{$userinfo.b_firstname}"> {if $reg_error ne "" and $userinfo.b_firstname eq "" && $default_fields.firstname.required eq 'Y'}<FONT class="Star">&lt;&lt;</FONT>{/if} </TD> </TR> {/if} {if $default_fields.lastname.avail eq 'Y'} <TR> <TD align="right">{$lng.lbl_last_name}</TD> <TD>{if $default_fields.lastname.required eq 'Y'}<FONT class="Star">*</FONT>{else}{/if}</TD> <TD nowrap> <INPUT type="text" name="b_lastname" size="32" maxlength="32" value="{$userinfo.b_lastname}"> {if $reg_error ne "" and $userinfo.b_lastname eq "" && $default_fields.lastname.required eq 'Y'}<FONT class="Star">&lt;&lt;</FONT>{/if} </TD> </TR> {/if} {/if}

To:

Code:
{if $default_fields.firstname.avail eq 'Y'} {if $js_enabled} <INPUT type="hidden" name="b_firstname" size="32" maxlength="32" value="{$userinfo.firstname}"> {else} <TR> <TD align="right">{$lng.lbl_first_name}</TD> <TD>{if $default_fields.firstname.required eq 'Y'}<FONT class="Star">*</FONT>{else}{/if}</TD> <TD nowrap> <INPUT type="text" name="b_firstname" size="32" maxlength="32" value="{$userinfo.b_firstname}"> {if $reg_error ne "" and $userinfo.b_firstname eq "" && $default_fields.firstname.required eq 'Y'}<FONT class="Star">&lt;&lt;</FONT>{/if} </TD> </TR> {/if} {/if} {if $default_fields.lastname.avail eq 'Y'} {if $js_enabled} <INPUT type="hidden" name="b_lastname" size="32" maxlength="32" value="{$userinfo.lastname}"> {else} <TR> <TD align="right">{$lng.lbl_last_name}</TD> <TD>{if $default_fields.lastname.required eq 'Y'}<FONT class="Star">*</FONT>{else}{/if}</TD> <TD nowrap> <INPUT type="text" name="b_lastname" size="32" maxlength="32" value="{$userinfo.b_lastname}"> {if $reg_error ne "" and $userinfo.b_lastname eq "" && $default_fields.lastname.required eq 'Y'}<FONT class="Star">&lt;&lt;</FONT>{/if} </TD> </TR> {/if} {/if} {/if}

Step 4:

Add a four (lines end with a semi colon) lines to the check_registerform_fields() function in customer/main/register.tpl:

Original function:

Code:
<SCRIPT type="text/javascript" language="JavaScript 1.2"> var is_run = false; function check_registerform_fields() {ldelim} if(is_run) return false; is_run = true; if (check_zip_code(){if $default_fields.email.avail eq 'Y'} && checkEmailAddress(document.registerform.email, '{$default_fields.email.required}'){/if} {if $config.General.check_cc_number eq "Y" AND $config.General.disable_cc ne "Y"}&& checkCCNumber(document.registerform.card_number,document.registerform.card_type) {/if}&& checkRequired('')) {ldelim} document.registerform.submit(); return true; {rdelim} is_run = false; return false; {rdelim} </SCRIPT>

Revised function:

Code:
<SCRIPT type="text/javascript" language="JavaScript 1.2"> var is_run = false; function check_registerform_fields() {ldelim} {if $js_enabled} document.registerform.b_firstname.value = document.registerform.firstname.value; document.registerform.b_lastname.value = document.registerform.lastname.value; {/if} if(is_run) return false; is_run = true; if (check_zip_code(){if $default_fields.email.avail eq 'Y'} && checkEmailAddress(document.registerform.email, '{$default_fields.email.required}'){/if} {if $config.General.check_cc_number eq "Y" AND $config.General.disable_cc ne "Y"}&& checkCCNumber(document.registerform.card_number,document.registerform.card_type) {/if}&& checkRequired('')) {ldelim} document.registerform.submit(); return true; {rdelim} is_run = false; return false; {rdelim} </SCRIPT>
__________________
r.jones
X-Cart Version 4.0.13
Reply With Quote