Jump to content

[SOLVED] Get value from input field in OrderOpcController


Recommended Posts

Hi,

I have problem with one page order. I add two checkbox under terms and conditions and now I want to check value but I dont know which method I should use...right now I have something like this:

if (Tools::isSubmit('myfield')){
            $sql = 'UPDATE `'._DB_PREFIX_.'customer` SET `optin` = 1 WHERE `id_customer` = '.$this->context->customer->id;
        }

In OrderOpcControllerCore and ParentOrderControllerCore I dont see postprocess. Thanks for any help.

Kind regards

--edit:

So what I have to this moment:

1. Two checkbox in order-carrier.tpl

2. In order-opc.js I add:

$('#personalData1').change(function () {
        $.ajax({
            type: 'POST',
            headers: {"cache-control": "no-cache"},
            url: orderOpcUrl + '?rand=' + new Date().getTime(),
            async: false,
            cache: false,
            dataType: "json",
            data: 'ajax=true&method=updatePersonalData1&personalData1=' + encodeURIComponent($('#personalData1').val()) + '&token=' + static_token,
            success: function (jsonData)
            {
                window.alert($('#personalData1').val());
                if (jsonData.hasError)
                {
                    
                    var errors = '';
                    for (var error in jsonData.errors)
                        //IE6 bug fix
                        if (error !== 'indexOf')
                            errors += $('<div />').html(jsonData.errors[error]).text() + "\n";
                    alert(errors);
                } 
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus !== 'abort')
                    alert("TECHNICAL ERROR: unable to save message \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);

            }
        });
    });

no errors:

3. In controllers\front\OrderOpcController.php:

if ($this->context->cart->nbProducts()) {
            if (Tools::isSubmit('ajax')) {
                if (Tools::isSubmit('method')) {
                    switch (Tools::getValue('method')) {
                        case 'updatePersonalData1':
                            Db::getInstance()->update(
                                        'customer', array(
                                    'optin' => '1'
                                        ), 'id_customer = ' . $this->context->customer->id
                                );
                            
                            $this->ajaxDie(true);
                            break;

 

 

Kind rigards

Edited by mr.suchy (see edit history)
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...