Prestashop模块错误"发生错误。请检查您的数据。"

时间:2018-02-23 16:55:41

标签: php ajax module prestashop prestashop-1.6

我正在使用Prestashop版本1.6.1.17。

我有一个名为" Blockcallmeback"的模块。此模块为客户添加选项以留下他/她的电话号码,以便您可以给他/她回电。

问题是提交表单后出现错误:

"发生错误。请检查您的数据。"

这意味着,ajax函数返回success = false,但我不知道为什么。

这是js代码:

<script type="text/javascript">
var blockcallme_url = "/casannabis/modules/blockcallme/ajax.php";
var blockcallme_text_please = "Please enter";
var blockcallme_text_please_phone = "your phone number";
var blockcallme_text_thanks = "Thank you. We will call you soon.";
var blockcallme_text_error = "An error occured. Please check your data.";
var blockcallme_mask = "+56 (9) 9999-9999";
$(function () {
    $("a.blockcallme_button").fancybox({
        'hideOnContentClick': false,
        'hideOnOverlayClick': true,
        'overlayOpacity': 0.4,
        'padding': 0,
        afterShow: function () {
            $('#blockcallme_phone').focus();
            $('#blockcallme_phone').inputmask({
                'mask': blockcallme_mask,
                "clearMaskOnLostFocus": false
            });
        }
    });

    $('.blockcallme_form').on('submit', function () {
        debugger;
        $('#blockcallme_loader').show();
        var form = $(this);
        $('.blockcallme_errors').html('').hide();
        $('.blockcallme_success').html('').hide();
        var success = true;
        var blockcallme_phone_input = $(this).find('#blockcallme_phone');
        if (!blockcallme_phone_input.val() || !blockcallme_phone_input.inputmask('isComplete')) {
            blockcallme_phone_input.css('outline', '1px solid red');
            setTimeout(function () {
                blockcallme_phone_input.css('outline', '');
            }, 1000);
            $(this).find('.blockcallme_errors').append(blockcallme_text_please + ' <span style="font-weight: bold;">' + blockcallme_text_please_phone + '</span>.<br>').show();
            success = false;
        }
        if (!success) {
            $('#blockcallme_loader').hide();
            return false;
        }
        $.ajax({
            type: 'POST',
            url: blockcallme_url + '?ajax=1&rand=' + new Date().getTime(),
            async: true,
            cache: false,
            dataType : "json",
            data: form.serialize(),
            success: function(jsonData) {
                debugger;
                $('#blockcallme_loader').hide();
                if (jsonData['success'] == 1) {
                    form.find('.blockcallme_success').html(blockcallme_text_thanks).show();
                }
                else {
                    form.find('.blockcallme_errors').html(blockcallme_text_error).show();
                }
            }
        });
        return false;
    });
});
</script>

这是php代码:

    <?php
    include_once(dirname(__FILE__) . '/../../config/config.inc.php');
    include_once(dirname(__FILE__) . '/../../init.php');

    if(Tools::getValue('ajax') == 1)
    {
            $name = pSQL(trim(Tools::getValue('blockcallme_name', '')));
            $phone = pSQL(trim(Tools::getValue('blockcallme_phone', '')));
            $blockcallme = Module::getInstanceByName('blockcallme');

            $success = 0;

            if(!empty($phone))
            {
                    Context::getContext()->cookie->blockcallme_phone = $phone;
                    Context::getContext()->cookie->blockcallme_name = $name;
                    $template = 'blockcallme';
                    $template_vars = array(
                            '{name}' => $name,
                            '{phone}' => $phone,
                    );

                    $email = Configuration::get('CALLME_EMAIL') ? Configuration::get('CALLME_EMAIL') : Configuration::get('PS_SHOP_EMAIL');
                    $to = array(
                            $email,
                    );

                    $send = Mail::Send(
                            Configuration::get('PS_LANG_DEFAULT'),
                            $template,
                            $blockcallme->l('Callback request', 'ajax'),
                            $template_vars,
                            $to,
                            null,
                            Configuration::get('PS_SHOP_EMAIL'),
                            Configuration::get('PS_SHOP_NAME'),
                            null,
                            null,
                            dirname(__FILE__).'/mails/'
                    );

                    if($send)
                            $success = 1;
            }

            if($success)
                    die(json_encode(array('success' => 1)));
            else
                    die(json_encode(array('success' => 0)));
    }

0 个答案:

没有答案