Page 1 of 1
Customer Account Form Validation
Posted: Mon Jan 26, 2009 4:30 pm
by Emmanuel
Has anyone made a complete javascript form validation for the customer account creation???
I can just about get away with putting anything into the fields and it goes through!
there needs to be something like: no alpha-keys in the phone and fax numbers and a good email validation script.....
Re: Customer Account Form Validation
Posted: Mon Jan 26, 2009 7:59 pm
by Qphoria
That wouldn't be done with javascript. That would be done on the server side. Similar to the way the minimum character count is checked (you obviously have to enter something in required fields).
It's quite easy to add additional validation checks.
Re: Customer Account Form Validation
Posted: Mon Jan 26, 2009 9:58 pm
by hm2k
You can do it both ways really.
Javascript validation is only ever advice, as the end user can easily over-ride it.
Instead, we use server-side validation.
Re: Customer Account Form Validation
Posted: Mon Jan 26, 2009 11:15 pm
by Qphoria
Email validation is already being checked for validity. I suppose we could add the actual dns check, but might be overkill.
For the phone and fax (assuming you are using at least v0.7.9 RC6):
EDIT: catalog/controller/account_create.php
FIND:
Code: Select all
if (!$validate->strlen($request->gethtml('telephone', 'post'),3,32)) {
$this->error['telephone'] = $language->get('error_telephone');
}
AFTER, ADD:
Code: Select all
if ([color=red]![/color]preg_match('/^[0-9:-]{[color=red]3[/color]}$/', $request->gethtml('telephone', 'post'))) {
$this->error['telephone'] = $language->get('error_telephone');
}
if ($request->gethtml('fax', 'post') != '') {
if ([color=red]![/color]preg_match('/^[0-9:-]{[color=red]3[/color]}$/', $request->gethtml('fax', 'post'))) {
$this->error['fax'] = $language->get('error_fax');
}
}
You will need to add an entry for the fax error in the language file, and update the message to be more clear of the possible errors:
EDIT: catalog/language/english/controller/account_create.php
FIND:
Code: Select all
$_['error_telephone'] = '* Telephone must be greater than 3 and less than 32 characters!';
REPLACE WITH:
Code: Select all
$_['error_telephone'] = '* Telephone must be greater than 3 and less than 32 characters and contain only numbers, dashes, or decimals!';
AFTER, ADD:
Code: Select all
$_['error_fax'] = '* Fax must be greater than 3 and less than 32 characters and contain only numbers, dashes, or decimals!';
Then edit the tpl file to add the fax error message
EDIT: catalog/template/default/content/account_create.tpl
FIND:
Code: Select all
<tr>
<td><?php echo $entry_fax; ?></td>
<td><input type="text" name="fax" value="<?php echo $fax; ?>"></td>
</tr>
REPLACE WITH:
Code: Select all
<tr>
<td><span class="required">*</span> <?php echo $entry_fax; ?></td>
<td><input type="text" name="fax" value="<?php echo $fax; ?>">
<?php if ($error_fax) { ?>
<span class="error"><?php echo $error_fax; ?></span>
<?php } ?></td>
</tr>
Re: Customer Account Form Validation
Posted: Tue Jan 27, 2009 4:59 am
by Emmanuel
Ok, that sounds good, I'll try it
Re: Customer Account Form Validation
Posted: Tue Jan 27, 2009 11:58 am
by Emmanuel
I pasted in the code but it didn't seem to work?
I would also like to make the postcode field mandatory..... is there something else I should be doing?

Re: Customer Account Form Validation
Posted: Tue Jan 27, 2009 12:36 pm
by Qphoria
Ah whoops, I forgot the !.. i updated the code above. (the second code block, the changes are in red)
If you want to make post code required, you can add the follow after that code from the second block above:
Code: Select all
if (!$validate->strlen($request->gethtml('postcode', 'post'),3,32)) {
$this->error['telephone'] = $language->get('error_postcode');
}
You will also have to create an error message in the language file, similar to how the existing telephone one was set up
Re: Customer Account Form Validation
Posted: Tue Jan 27, 2009 1:21 pm
by Emmanuel
Thanks
