Fixed: No validation for length of characters in traveller detail fields in Front and Back office
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
*}
|
||||
|
||||
<div class="modal-body">
|
||||
<div class="text-left errors-wrap"></div>
|
||||
<form id="customer-guest-details-form">
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-2">
|
||||
|
||||
@@ -78,6 +78,31 @@ class CartCustomerGuestDetailCore extends ObjectModel
|
||||
if (!trim($this->phone) || !Validate::isPhoneNumber($this->phone)) {
|
||||
$isValid = false;
|
||||
}
|
||||
|
||||
$className = 'CartCustomerGuestDetail';
|
||||
$rules = call_user_func(array($className, 'getValidationRules'), $className);
|
||||
|
||||
if (isset($rules['size']['firstname'])) {
|
||||
if (Tools::strlen(trim($this->firstname)) > $rules['size']['firstname']) {
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
if (isset($rules['size']['lastname'])) {
|
||||
if (Tools::strlen(trim($this->lastname)) > $rules['size']['lastname']) {
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
if (isset($rules['size']['email'])) {
|
||||
if (Tools::strlen(trim($this->email)) > $rules['size']['email']) {
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
if (isset($rules['size']['phone'])) {
|
||||
if (Tools::strlen(trim($this->phone)) > $rules['size']['phone']) {
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
}
|
||||
@@ -34,12 +34,12 @@ class OrderCustomerGuestDetailCore extends ObjectModel
|
||||
'table' => 'order_customer_guest_detail',
|
||||
'primary' => 'id_order_customer_guest_detail',
|
||||
'fields' => array(
|
||||
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'id_order' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'id_gender' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'),
|
||||
'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'size' => 32),
|
||||
'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'size' => 32),
|
||||
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128),
|
||||
'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32),
|
||||
'firstname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'size' => 32, 'required' => true),
|
||||
'lastname' => array('type' => self::TYPE_STRING, 'validate' => 'isName', 'size' => 32, 'required' => true),
|
||||
'email' => array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128, 'required' => true),
|
||||
'phone' => array('type' => self::TYPE_STRING, 'validate' => 'isPhoneNumber', 'size' => 32, 'required' => true),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
),
|
||||
@@ -53,22 +53,4 @@ class OrderCustomerGuestDetailCore extends ObjectModel
|
||||
WHERE `id_order` = '.(int)$id_order
|
||||
);
|
||||
}
|
||||
|
||||
public function validateGuestInfo()
|
||||
{
|
||||
$isValid = true;
|
||||
if (!trim($this->firstname) || !Validate::isName($this->firstname)) {
|
||||
$isValid = false;
|
||||
}
|
||||
if (!trim($this->lastname) || !Validate::isName($this->lastname)) {
|
||||
$isValid = false;
|
||||
}
|
||||
if (!trim($this->email) || !Validate::isEmail($this->email)) {
|
||||
$isValid = false;
|
||||
}
|
||||
if (!trim($this->phone) || !Validate::isPhoneNumber($this->phone)) {
|
||||
$isValid = false;
|
||||
}
|
||||
return $isValid;
|
||||
}
|
||||
}
|
||||
@@ -3111,44 +3111,52 @@ class AdminOrdersControllerCore extends AdminController
|
||||
public function ajaxProcessUpdateGuestDetails()
|
||||
{
|
||||
$response = array(
|
||||
'success' => false
|
||||
'hasError' => false,
|
||||
'errors' => array(),
|
||||
);
|
||||
if (Validate::isLoadedObject($order = new Order(Tools::getValue('id_order')))) {
|
||||
if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) {
|
||||
if (Validate::isLoadedObject($objCustomerGuestDetail = new OrderCustomerGuestDetail($id_customer_guest_detail))) {
|
||||
$id_gender = Tools::getValue('id_gender');
|
||||
$firstname = Tools::getValue('firstname');
|
||||
$lastname = Tools::getValue('lastname');
|
||||
$email = Tools::getValue('email');
|
||||
$phone = Tools::getValue('phone');
|
||||
$objCustomerGuestDetail->id_gender = $id_gender;
|
||||
$objCustomerGuestDetail->firstname = $firstname;
|
||||
$objCustomerGuestDetail->lastname = $lastname;
|
||||
$objCustomerGuestDetail->email = $email;
|
||||
$objCustomerGuestDetail->phone = $phone;
|
||||
if ($objCustomerGuestDetail->validateGuestInfo()) {
|
||||
$objCustomerGuestDetail = new OrderCustomerGuestDetail();
|
||||
$response['errors'] = $objCustomerGuestDetail->validateController();
|
||||
if (!$response['errors']) {
|
||||
if ($id_customer_guest_detail = OrderCustomerGuestDetail::isCustomerGuestBooking($order->id)) {
|
||||
if (Validate::isLoadedObject($objCustomerGuestDetail = new OrderCustomerGuestDetail($id_customer_guest_detail))) {
|
||||
$id_gender = Tools::getValue('id_gender');
|
||||
$firstname = Tools::getValue('firstname');
|
||||
$lastname = Tools::getValue('lastname');
|
||||
$email = Tools::getValue('email');
|
||||
$phone = Tools::getValue('phone');
|
||||
$objCustomerGuestDetail->id_gender = $id_gender;
|
||||
$objCustomerGuestDetail->firstname = $firstname;
|
||||
$objCustomerGuestDetail->lastname = $lastname;
|
||||
$objCustomerGuestDetail->email = $email;
|
||||
$objCustomerGuestDetail->phone = $phone;
|
||||
if ($objCustomerGuestDetail->save()) {
|
||||
$response['success'] = true;
|
||||
$gender = new Gender($objCustomerGuestDetail->id_gender, $this->context->language->id);
|
||||
$response['data']['gender_name'] = $gender->name;
|
||||
$response['data']['guest_name'] = $objCustomerGuestDetail->firstname.' '.$objCustomerGuestDetail->lastname ;
|
||||
$response['data']['guest_email'] = $objCustomerGuestDetail->email;
|
||||
$response['data']['guest_phone'] = $objCustomerGuestDetail->phone;
|
||||
|
||||
$response['msg'] = $this->l('Guest details are updated.');
|
||||
} else {
|
||||
$response['errors'][] = $this->l('Unable to save guest details.');
|
||||
}
|
||||
} else {
|
||||
$response['errors'][] = $this->l('Invalid guest details, please check and try again.');
|
||||
$response['errors'][] = $this->l('Guest details not found.');
|
||||
}
|
||||
} else {
|
||||
$response['errors'][] = $this->l('Guest details not found.');
|
||||
}
|
||||
} else {
|
||||
$response['errors'][] = $this->l('Guest details not found.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($response['errors']) {
|
||||
$response['hasError'] = true;
|
||||
$this->context->smarty->assign('errors', $response['errors']);
|
||||
|
||||
$response['errorsHtml'] = $this->context->smarty->fetch('alerts.tpl');
|
||||
}
|
||||
|
||||
$this->ajaxDie(json_encode($response));
|
||||
}
|
||||
|
||||
|
||||
@@ -1078,21 +1078,52 @@ class OrderOpcControllerCore extends ParentOrderController
|
||||
$customerGuestDetailLastname = Tools::getValue('customer_guest_detail_lastname');
|
||||
$customerGuestDetailEmail = Tools::getValue('customer_guest_detail_email');
|
||||
$customerGuestDetailPhone = Tools::getValue('customer_guest_detail_phone');
|
||||
|
||||
$className = 'CartCustomerGuestDetail';
|
||||
$rules = call_user_func(array($className, 'getValidationRules'), $className);
|
||||
|
||||
if (trim($customerGuestDetailGender) && Validate::isUnsignedInt($customerGuestDetailGender)) {
|
||||
$objCustomerGuestDetail->id_gender = $customerGuestDetailGender;
|
||||
} else {
|
||||
$result['errors']['customer_guest_detail_gender'] = Tools::displayError('Invalid gender');
|
||||
}
|
||||
if (trim($customerGuestDetailFirstname) && Validate::isName($customerGuestDetailFirstname)) {
|
||||
|
||||
if (trim($customerGuestDetailFirstname)
|
||||
&& Validate::isName($customerGuestDetailFirstname)
|
||||
&& (!isset($rules['size']['firstname'])
|
||||
|| (isset($rules['size']['firstname']) && (Tools::strlen(trim($customerGuestDetailFirstname)) <= $rules['size']['firstname']))
|
||||
)
|
||||
) {
|
||||
$objCustomerGuestDetail->firstname = $customerGuestDetailFirstname;
|
||||
}
|
||||
if (trim($customerGuestDetailLastname) && Validate::isName($customerGuestDetailLastname)) {
|
||||
|
||||
if (trim($customerGuestDetailLastname)
|
||||
&& Validate::isName($customerGuestDetailLastname)
|
||||
&& (!isset($rules['size']['lastname'])
|
||||
|| (isset($rules['size']['lastname']) && (Tools::strlen(trim($customerGuestDetailLastname)) <= $rules['size']['lastname']))
|
||||
)
|
||||
) {
|
||||
$objCustomerGuestDetail->lastname = $customerGuestDetailLastname;
|
||||
}
|
||||
if (trim($customerGuestDetailEmail) && Validate::isEmail($customerGuestDetailEmail)) {
|
||||
|
||||
if (trim($customerGuestDetailEmail)
|
||||
&& Validate::isEmail($customerGuestDetailEmail)
|
||||
&& (!isset($rules['size']['email'])
|
||||
|| (isset($rules['size']['email']) && (Tools::strlen(trim($customerGuestDetailEmail)) <= $rules['size']['email']))
|
||||
)
|
||||
) {
|
||||
$objCustomerGuestDetail->email = $customerGuestDetailEmail;
|
||||
}
|
||||
if (trim($customerGuestDetailPhone) && Validate::isPhoneNumber($customerGuestDetailPhone)) {
|
||||
|
||||
if (trim($customerGuestDetailPhone)
|
||||
&& Validate::isPhoneNumber($customerGuestDetailPhone)
|
||||
&& (!isset($rules['size']['phone'])
|
||||
|| (isset($rules['size']['phone']) && (Tools::strlen(trim($customerGuestDetailPhone)) <= $rules['size']['phone']))
|
||||
)
|
||||
) {
|
||||
$objCustomerGuestDetail->phone = $customerGuestDetailPhone;
|
||||
}
|
||||
|
||||
$objCustomerGuestDetail->id_cart = $this->context->cart->id;
|
||||
$objCustomerGuestDetail->save();
|
||||
} else {
|
||||
@@ -1102,6 +1133,7 @@ class OrderOpcControllerCore extends ParentOrderController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->cart->save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2191,6 +2191,7 @@ const TravellerModal = {
|
||||
},
|
||||
submit: function() {
|
||||
$(".loading_overlay").show();
|
||||
TravellerModal.hideErrors();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
headers: {
|
||||
@@ -2201,7 +2202,9 @@ const TravellerModal = {
|
||||
cache: false,
|
||||
data: $('#customer-guest-details-form').serialize()+'&ajax=true&id_order='+id_order+'&action=updateGuestDetails',
|
||||
success: function(result) {
|
||||
if (result.success) {
|
||||
if (result.hasError == true) {
|
||||
TravellerModal.showErrors(result.errorsHtml);
|
||||
} else {
|
||||
if (result.msg) {
|
||||
showSuccessMessage(result.msg);
|
||||
}
|
||||
@@ -2218,14 +2221,20 @@ const TravellerModal = {
|
||||
if (result.data.guest_phone) {
|
||||
$('#customer-guest-details .guest_phone a').attr('href', 'tel'+result.data.guest_phone).html('<i class="icon-phone"></i> ' + result.data.guest_phone);
|
||||
}
|
||||
} else if (result.errors) {
|
||||
showErrorMessage(result.errors);
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
$(".loading_overlay").hide();
|
||||
}
|
||||
});
|
||||
},
|
||||
showErrors: function(errorsHtml) {
|
||||
$('#traveller-modal .errors-wrap').html(errorsHtml);
|
||||
$('#traveller-modal .errors-wrap').show(200);
|
||||
},
|
||||
hideErrors: function(cb) {
|
||||
$('#traveller-modal .errors-wrap').hide(200);
|
||||
$('#traveller-modal .errors-wrap').html('');
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -175,6 +175,11 @@ function validate_isPasswd(s)
|
||||
return (s.length >= 5 && s.length < 255);
|
||||
}
|
||||
|
||||
function validate_maxSize(s, maxSize)
|
||||
{
|
||||
return (s.length <= maxSize);
|
||||
}
|
||||
|
||||
function validate_field(that)
|
||||
{
|
||||
if ($(that).hasClass('is_required') || $(that).val().length)
|
||||
@@ -191,6 +196,15 @@ function validate_field(that)
|
||||
else if($(that).attr('data-validate'))
|
||||
var result = window['validate_' + $(that).attr('data-validate')]($(that).val());
|
||||
if (result) {
|
||||
if ($(that).attr('data-maxSize')) {
|
||||
var maxSize = $(that).attr('data-maxSize');
|
||||
var resultmaxSize = validate_maxSize($(that).val(), maxSize);
|
||||
if (!resultmaxSize) {
|
||||
$(that).parent().addClass('form-error').removeClass('form-ok');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$(that).parent().removeClass('form-error').addClass('form-ok');
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -98,23 +98,23 @@
|
||||
</div>
|
||||
<div class="required form-group col-sm-5">
|
||||
<label for="firstname">{l s='First name'} <sup>*</sup></label>
|
||||
<input type="text" class="text form-control validate is_required" id="customer_guest_detail_firstname" name="customer_guest_detail_firstname" data-validate="isName"{if isset($smarty.post.customer_guest_detail_firstname) && $smarty.post.customer_guest_detail_firstname} value="{$smarty.post.customer_guest_detail_firstname}"{elseif isset($customer_guest_detail) && $customer_guest_detail.firstname} value="{$customer_guest_detail.firstname}"{/if}/>
|
||||
<input type="text" class="text form-control validate is_required" id="customer_guest_detail_firstname" name="customer_guest_detail_firstname" data-validate="isName" data-maxSize="32"{if isset($smarty.post.customer_guest_detail_firstname) && $smarty.post.customer_guest_detail_firstname} value="{$smarty.post.customer_guest_detail_firstname}"{elseif isset($customer_guest_detail) && $customer_guest_detail.firstname} value="{$customer_guest_detail.firstname}"{/if}/>
|
||||
</div>
|
||||
<div class="required form-group col-sm-5">
|
||||
<label for="lastname">{l s='Last name'} <sup>*</sup></label>
|
||||
<input type="text" class="form-control validate is_required" id="customer_guest_detail_lastname" name="customer_guest_detail_lastname" data-validate="isName"{if isset($smarty.post.customer_guest_detail_lastname) && $smarty.post.customer_guest_detail_lastname} value="{$smarty.post.customer_guest_detail_lastname}"{elseif isset($customer_guest_detail) && $customer_guest_detail.lastname} value="{$customer_guest_detail.lastname}"{/if}/>
|
||||
<input type="text" class="form-control validate is_required" id="customer_guest_detail_lastname" name="customer_guest_detail_lastname" data-validate="isName" data-maxSize="32"{if isset($smarty.post.customer_guest_detail_lastname) && $smarty.post.customer_guest_detail_lastname} value="{$smarty.post.customer_guest_detail_lastname}"{elseif isset($customer_guest_detail) && $customer_guest_detail.lastname} value="{$customer_guest_detail.lastname}"{/if}/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="required text form-group col-sm-6">
|
||||
<label for="email">{l s='Email'} <sup>*</sup></label>
|
||||
<input type="email" class="text form-control validate is_required" id="customer_guest_detail_email" name="customer_guest_detail_email" data-validate="isEmail"{if isset($smarty.post.customer_guest_detail_email) && $smarty.post.customer_guest_detail_email} value="{$smarty.post.customer_guest_detail_email}"{elseif isset($customer_guest_detail) && $customer_guest_detail.email} value="{$customer_guest_detail.email}"{/if}/>
|
||||
<input type="email" class="text form-control validate is_required" id="customer_guest_detail_email" name="customer_guest_detail_email" data-validate="isEmail" data-maxSize="128"{if isset($smarty.post.customer_guest_detail_email) && $smarty.post.customer_guest_detail_email} value="{$smarty.post.customer_guest_detail_email}"{elseif isset($customer_guest_detail) && $customer_guest_detail.email} value="{$customer_guest_detail.email}"{/if}/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="{if isset($one_phone_at_least) && $one_phone_at_least}required {/if}form-group col-sm-6">
|
||||
<label for="phone_mobile">{l s='Mobile phone'}{if isset($one_phone_at_least) && $one_phone_at_least} <sup>**</sup>{/if}</label>
|
||||
<input type="text" class="text form-control validate is_required" name="customer_guest_detail_phone" id="customer_guest_detail_phone" data-validate="isPhoneNumber"{if isset($smarty.post.customer_guest_detail_phone) && $smarty.post.customer_guest_detail_phone} value="{$smarty.post.customer_guest_detail_phone}"{elseif isset($customer_guest_detail) && $customer_guest_detail.phone} value="{$customer_guest_detail.phone}"{/if}/>
|
||||
<input type="text" class="text form-control validate is_required" name="customer_guest_detail_phone" id="customer_guest_detail_phone" data-validate="isPhoneNumber" data-maxSize="32"{if isset($smarty.post.customer_guest_detail_phone) && $smarty.post.customer_guest_detail_phone} value="{$smarty.post.customer_guest_detail_phone}"{elseif isset($customer_guest_detail) && $customer_guest_detail.phone} value="{$customer_guest_detail.phone}"{/if}/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -515,4 +515,4 @@
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user