验证Opencart [英] Validation Opencart
问题描述
我想在opencart代码示例中添加php电话号码验证
i want to add php phone number validation in opencart code sample is given below
if(!filter_var($customer_email, FILTER_VALIDATE_EMAIL)) {
$errors[$pos++] = 'Email is not valid.';
}
if($customer_mobile=='') {
$errors[$pos++] = 'Please enter your Mobile.';
} /*elseif (strlen($customer_mobile) < 11 || !is_numeric($this->request->post['cell_number'])){
$errors[$pos++] = 'Mobile number should be 7 digits.';
}*/
推荐答案
@Tayyab Gulsher Vohra ....
@Tayyab Gulsher Vohra....
我也面临这个问题.我总结自己并做到了.
按照说明进行操作.
opencart是一个 MVC结构平台,因此您需要了解Controller,Model和view,在这里Controller是index()
function
I am also facing this problem.I concluded myself and made it.
follow the instruction.,
The opencart is a MVC structure platform,so you need to know about Controller , Model and view ,Here Controller is first initialization telephone number in index()
function
if (isset($this->request->post['telephone'])) {
$this->data['telephone'] = $this->request->post['telephone'];
} else {
$this->data['telephone'] = $this->customer->getTelephone();
}
此外,使用此方法,电话号码必须有效.
further, telephone number must be valid using this method.,
function validate()
if( !preg_match("/^([1]-)?[0-9]{3}-[0-9]{3}-[0-9]{4}$/i", $this->request->post['telephone']) ) {
$this->error['telephone'] = $this->language->get('error_telephone');
}
然后应在语言文件中初始化电话号码值.
then you should be initialized telephone number value in language file.
这篇关于验证Opencart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!