How to activate the reg exp validation ?

  • Posts: 28
  • Thank you received: 1
8 years 8 months ago #234032

-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.5
-- Browser(s) name and version -- : Firefox 45.0.1

Hi.

I want to add a RegExp on the postcode, using a custom field, to match the french postal codes format.
I've set the RegExp in my custom field, but it doesn't work (the form is validated, even if I key in unauthorized characters).
Is there someting I'm missing (like an option to activate), to get the RegExp work ?

Thanks in advance for your help

plastic1st

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #234037

Hi,

Is the field "required" ? The regex will only be used if the field is required.

Please Log in or Create an account to join the conversation.

  • Posts: 28
  • Thank you received: 1
8 years 8 months ago #234123

Hello Nicolas.

Thanks for your answer.
The field is required. If I let it empty, the field control is done, and I get an error message.
Only the RegExp does not work.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 8 months ago #234136

Hi,

Then it's probably that the regex you put there is wrong. Could you do a screenshot of the settings of your custom field and provide a link to the page where it is displayed ?

Please Log in or Create an account to join the conversation.

  • Posts: 28
  • Thank you received: 1
8 years 7 months ago #234264

I've tried different RegExps, including RegExps found on the forum, but none of these did work.
You'll find attached a screenshot of the custom field.

You can test it here :
s330101700.onlinehome.fr/coopt_v2/entrep...sentation-des-offres
Click on an image to select an offer and get redirected to the cart.
You need to login to test the field.

I send you login/password on PM.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
8 years 7 months ago #234283

Hi,

The problem is that the regex on the custom address fields are not handled properly for the address edition when using the another address selector than the popup one, which is the case on your website.
Add the code:

function check(&$field,&$value,$oldvalue){
		$status = parent::check($field,$value,$oldvalue);
		if($status && $field->field_required && !empty($field->field_options['regex'])){
			if(!preg_match('/'.str_replace('/','\/',$field->field_options['regex']).'/',$value)){
				$status = false;
				if(!empty($this->report)) {
					if(!empty($field->field_options['errormessage'])){
						$message = $this->trans($field->field_options['errormessage']);
					}else{
						$message = JText::sprintf('PLEASE_FILL_THE_FIELD', $this->trans($field->field_realname));
					}
					if($this->report === true) {
						$app = JFactory::getApplication();
						$app->enqueueMessage($message, 'error');
					} else {
						$this->parent->messages[] = array(
							$message,
							'error'
						);
					}
				}
			}
		}
		
		return $status;
	}
after the code:
class hikashopText extends hikashopItem {
	var $type = 'text';
	var $class = 'inputbox';
in the file administrator/components/com_hikashop/classes/field.php and that should fix the problem.

The following user(s) said Thank You: plastic1st

Please Log in or Create an account to join the conversation.

  • Posts: 28
  • Thank you received: 1
8 years 7 months ago #234500

Hello Nicolas.

Sorry for the long time before answering... I had no access to the Internet during the week end.

Thank you very much for your help.
It works like a charm ! :cheer:

Please Log in or Create an account to join the conversation.

Time to create page: 0.063 seconds
Powered by Kunena Forum