Jump to content

Validation email form Prestashop 1.6


Recommended Posts

Hi everyone!
I need help to validate email field, I need with the format @ and . I Tried with (filter_var($email, FILTER_VALIDATE_EMAIL)) and (!strstr($email,"\\")) && (!strstr($email,"\$")) && (!strstr($email," "))) but dont work.

AJAX.PHP

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

if (Tools::getValue('ajax') == 1) {
    $bon_order_name = pSQL(trim(Tools::getValue('bon_order_name', '')));
    $bon_order_phone = pSQL(trim(Tools::getValue('bon_order_phone', '')));		$bon_order_email = pSQL(trim(Tools::getValue('bon_order_email', '')));		$bon_order_mensaje = pSQL(trim(Tools::getValue('bon_order_mensaje', '')));
    $id_product = (int)trim(Tools::getValue('bon_order_id_product', ''));
    $product = new Product($id_product);
    $bon_order = Module::getInstanceByName('bonorder');
    $success = 0;

    if (!empty($bon_order_phone)) {
        Context::getContext()->cookie->bon_order_phone = $bon_order_phone;
        Context::getContext()->cookie->bon_order_name = $bon_order_name;				Context::getContext()->cookie->bon_order_email = $bon_order_email;				Context::getContext()->cookie->bon_order_mensaje = $bon_order_mensaje;
        $template = 'bonorder';
        $template_vars = array(
            '{name}' => $bon_order_name,
            '{phone}' => $bon_order_phone,						'{email}' => $bon_order_email,						'{mensaje}' => $bon_order_mensaje,
            '{product_name}' => Product::getProductName($id_product) . ', ' . $product->reference,
            '{product_link}' => Context::getContext()->link->getProductLink($id_product),
        );

        $email = Configuration::get('BON_ORDER_EMAIL');

        $to = array(
            $email,
        );

        $send = Mail::Send(
            Configuration::get('PS_LANG_DEFAULT'),
            $template,
            $bon_order->l('Consulta de Producto', 'ajax'),
            $template_vars,
            $to,
            null,
            Configuration::get('BON_ORDER_EMAIL'),
            Configuration::get('PS_SHOP_NAME'),
            null,
            null,
            dirname(__FILE__).'/mails/'
        );

        if ($send) {
            $success = 1;
        }
    }

    if ($success) {
        die(Tools::jsonEncode(array('success' => 1)));
    } else {
        die(Tools::jsonEncode(array('success' => 0)));
    }
}

 

BONORDER.JS
 

$(function () {
    $(".btn-bonorder").fancybox({
        'hideOnContentClick': false,
        'hideOnOverlayClick': true,
        'overlayOpacity': 0.4,
        'padding': 0,
    });

    $('.bon_order_errors').hide();
    $('.bon_order_success').hide();
    $('.bon_order_errors_phone').hide();

    $('.btn-bonorder').on('click', function () {
        $('.bon_order_box').show();
        $('.bonorder_send').show();
        $('.bon_order_success').hide();
    });

    $('.bonorder_form').on('submit', function () {

       var success = true,
           bon_order_phone = $(this).find('#bon_order_phone');

       if (!bon_order_phone.val()) {
           bon_order_phone.css('outline', '1px solid red');
           setTimeout(function () {
               bon_order_phone.css('outline', '');
           }, 500);
           $(this).find('.bon_order_errors_phone').show();
           $('.bon_order_errors').hide();
           success = false;
       }

       $.ajax({
            type: 'POST',
            url: bon_order_url + '?ajax=1&rand=' + new Date().getTime(),
            async: true,
            cache: false,
            dataType : "json",
            data: $(this).serialize(),
            success: function(jsonData) {
                if (jsonData['success'] == 1) {
                    $('.bon_order_success').show();
                    $('.bon_order_box').hide();
                    $('.bonorder_send').hide();
                    $('.bon_order_errors').hide();
                    $('.bon_order_errors_phone').hide();
                } else {
                    $('.bon_order_errors').show();
                    if (!bon_order_phone.val()) {
                        $('.bon_order_errors').hide();
                    }
                }
            }
        });

        return false;
    });
});

 

 

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...