есть 3 поля
<input class="form-control" type="text" name="firstname">
<input class="form-control" type="text" name="firstname2">
<input class="form-control" type="text" name="firstname3">
Передаю данные ajax
$(document).on("click touchstart", "#forder-submit", function (e) {
$.ajax({
url: 'index.php?route=module/for/write',
type: 'post',
dataType: 'json',
data: $('input[name=\'firstname\'],input[name=\'firstname2\'],input[name=\'firstname3\']'),
success: function (data) {
if (data['error']) {
$('.for .error').remove();
if (data['error']['firstname']) {
$('.catapulta_error').html('<span class="text-danger">'+data['error']['contact']+'</span>').show();
}
if (data['error']['firstname2']) {
$('.catapulta_error').html('<span class="text-danger">'+data['error']['firstname']+'</span>').show();
}
if (data['error']['firstname3']) {
$('.catapulta_error').html('<span class="text-danger">'+data['error']['firstname2']+'</span>').show();
}
}
if (data['success']) {
$.magnificPopup.close();
$.magnificPopup.open({
items: {
src: 'index.php?route=module/for/success'
},
type: 'ajax'
});
}
}
});
});
Php
$firstname = $this->request->post['firstname '];
$firstname2 = $this->request->post['firstname2 '];
$firstname3= $this->request->post['firstname3 '];
Если например я хочу скрыть поле firstname, я удаляю
<input class="form-control" type="text" name="firstname">
(валидации нет) , но в таком случае поп ап окно не закрывается и не пишет в БД (firstname = '" . $this->db->escape($data['firstname2']) . "',)
Сделал
$firstname2 = (empty($this->request->post['catapulta_firstname2']) ? 'Не указано' : $this->request->post['catapulta_firstname2']);
Есть ли другой метод?