Post by Emmanuel » Mon Jan 26, 2009 4:30 pm

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.....

New member

Posts

Joined
Thu Oct 02, 2008 2:46 pm

Post by Qphoria » Mon Jan 26, 2009 7:59 pm

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.
Last edited by Qphoria on Mon Jan 26, 2009 8:03 pm, edited 1 time in total.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by hm2k » Mon Jan 26, 2009 9:58 pm

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.

UK Web Hosting


User avatar
Global Moderator

Posts

Joined
Tue Mar 11, 2008 9:06 am
Location - UK

Post by Qphoria » Mon Jan 26, 2009 11:15 pm

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>
Last edited by Qphoria on Tue Jan 27, 2009 12:40 pm, edited 1 time in total.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Emmanuel » Tue Jan 27, 2009 4:59 am

Ok, that sounds good, I'll try it

New member

Posts

Joined
Thu Oct 02, 2008 2:46 pm

Post by Emmanuel » Tue Jan 27, 2009 11:58 am

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? :-\

New member

Posts

Joined
Thu Oct 02, 2008 2:46 pm

Post by Qphoria » Tue Jan 27, 2009 12:36 pm

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
Last edited by Qphoria on Tue Jan 27, 2009 12:38 pm, edited 1 time in total.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Emmanuel » Tue Jan 27, 2009 1:21 pm

Thanks  ;)

New member

Posts

Joined
Thu Oct 02, 2008 2:46 pm
Who is online

Users browsing this forum: No registered users and 4 guests