Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Javascript validation of extra field in create edit account

Javascript validation of extra field in create edit account

Locked

Views: 3,363

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
28 Mar 2009, 5:06 PM
#1
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,872
Plugin Contributions:
7

Javascript validation of extra field in create edit account

Hi,
I need some pointers regarding Javascript validation.

I have added a tax id field to the create and edit account pages. I wish to validate this field.

Using edit account for illustration purposes the core javascript validation routine is
\includes\modules\pages\account_edit\jscript_form_check.php

I have added my routine in the same folder
\includes\modules\pages\account_edit\jscript_form_check_NIF.php

This is being included and is validating correctly but I have had to modify the core file jscript_form_check.php to call this extra routine during the form validation.

check_dni("taxid", <?php echo ENTRY_TAXID_NUMBER_LENGTH; ?>, "<?php echo ENTRY_TAXID_NUMBER_ERROR; ?>");

In the interests of code-elegance/education, is it possible to call this extra routine WITHOUT modifying the core code jscript_form_check.php?
If so how? I am an educated cut-and-paste trial-and-error coder and not much more, so be gentle.

Regards
Steve

29 Mar 2009, 3:40 PM
#2
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Javascript validation of extra field in create edit account

The easiest way to get this to work without modifying the core jscript file is to duplicate the function check_form in your own jscript file (call it another name like check_my_form), and add your call to the check_dni function within it.

Then edit override copies of the account_edit, create_account and login templates, changing the onsubmit function to use check_my_form instead of check_form.

29 Mar 2009, 8:52 PM
#3
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,872
Plugin Contributions:
7

Re: Javascript validation of extra field in create edit account

Thanks for that.

The only thing "wrong" is that the original jscript_check.form.php gets loaded too (as does any jscript*.) in addition to the new code unless you move it/delete it out of the folder, which sort of defeats the aim of trying to leave original code intact.
Still, worth a try, you can't have everything I guess.

regards
Steve

29 Mar 2009, 10:35 PM
#4
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: Javascript validation of extra field in create edit account

Unless you copy all the individual form field check functions in the original, you actually still need to load it for your custom form check to work...

20 Jul 2010, 7:47 PM
#5
fadi21 avatar

fadi21

New Zenner

Join Date:
Jul 2010
Location:
Egypt
Posts:
48
Plugin Contributions:
0

Re: Javascript validation of extra field in create edit account

dear : torvista
I'm new to zen-cart and i need to do the same (adding new field to create account page )

can you help plz ?

20 Jul 2010, 10:25 PM
#6
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,872
Plugin Contributions:
7

Re: Javascript validation of extra field in create edit account

this thread will show the way:
"Add a field into create account"

http://www.zen-cart.com/forum/showthread.php?t=73181