0

I have a function in my module.php file:

public function evo_admin_pb() {            
        $this->EE->load->library('db/cache_mproc', '', 'qodb');
        $this->EE->load->model('store');
        $this->EE->cp->set_breadcrumb($this->_base_url, lang('qo5_module_name'));
        $this->EE->cp->set_variable('cp_page_title', lang('evo_admin_pb'));

        $data = array(
            'pizza_type_form_action' => $this->_form_base . AMP . 'method=evo_select_pizza_type'
        );
        $data['_theme_base_url'] = $this->_theme_base_url;

        $results = $this->EE->db->query("SELECT type_extra_id, friendly_desc FROM exp_qo5_pbev_type_extras WHERE extra_type = 'Finisher' ORDER BY friendly_desc");

        if ($results->num_rows() > 0) {
            foreach ($results->result_array() as $row) {
                $data['finishers'][$row['type_extra_id']] =  $row['friendly_desc'];
            }
        }

        $data['crust_images'] = $this->get_asset_dir('evo_pb/crust/', '', TRUE);

        if(isset($_SESSION['evo_pb_admin_crust']) && isset($_SESSION['evo_pb_admin_size']) && isset($_SESSION['evo_pb_admin_finisher'])){
            $data['evo_selected_crust'] = $_SESSION['evo_pb_admin_crust'];
            $data['evo_selected_size'] = $_SESSION['evo_pb_admin_size'];
            $data['evo_selected_finisher'] = $_SESSION['evo_pb_admin_finisher'];
        }
        else if ($this->EE->input->post('action', TRUE) == 'edit') {
            error_log("edit");
            $data['evo_selected_crust'] = $this->EE->input->post('crust', true);
            $data['evo_selected_size'] = $this->EE->input->post('size', true);
            $data['evo_selected_finisher'] = $this->EE->input->post('finisher', true);
        }
        error_log("data going into view")        ;
        error_log(print_r($data, 1));
        return $this->EE->load->view('pizzabuilder/evo_admin_pb', $data, TRUE);
    }

The function is called two ways: first way is from a link that changes the URL directly so something like http://my_site.com/ap.php?C=addons_modules&M=show_module_cp&module=qo5&method=evo_admin_pb. This works correctly and loads the template as shown in the last line of the function.

The other way is from another javascript function:

function editCrustConfig(size, crust, finisher) {
    $.ajax({
            type : 'POST',
            url : EE.BASE + '&C=addons_modules&M=show_module_cp&module=qo5&method=evo_admin_pb',
            dataType : 'json',
            data: {
                action: 'edit',
                size: size,
                crust: crust,
                finisher: finisher
            }
        });
}

There are a series of HTML table rows generated in another view that each has a link which calls the js function like this: javascript:editCrustConfig( 'M', 'H', 'MA'). This doesn't work correctly, and I'm not sure why. editCrustConfig is running, and calling the evo_admin_pb function. It's getting all the way to the end of the function, and the error logging of the data being passed in to the view is correct. The only thing that isn't happening is the view actually loading.

What am I doing wrong? (We're on 2.5.2.)

1 Answer 1

1

It's most likely a missing CSRF token that's tripping you up. You can test whether this is the cause by temporarily turning off Secure Forms in Admin > Security & Sessions. If that is indeed the cause, try adding this to your data in editCrustConfig:

        data: {
            XID: EE.XID,
            action: 'edit',
            size: size,
            crust: crust,
            finisher: finisher
        }
2
  • Thanks, but that's not it. I added it, and get the same result. The strange thing is, when I look at the post/response in Firebug, the response contains the HTML for the view that's supposed to load. It just never actually visibly loads in the browser.
    – EmmyS
    Sep 22, 2014 at 21:17
  • @EmmyS, is that because you don't have any code to take the data from the response and insert it into the page? Take a look at the success property in the documentation. Aug 5, 2016 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.