Post by haosmark » Fri Dec 28, 2012 9:37 am

I can't figure out how to submit a form and display back the result.
Here's what I did:
in product.tpl I added:

Code: Select all

        <form action="<?php echo $action ?>" method="GET">
            <input type="text" length="15" limit="5" name="zip_code" />
            <input type="submit" value="estimate" name="submit" />
        </form>
to provide an input field. Then I went to catalog -> controller and modified product.php bu adding a method:

Code: Select all

    public function estimate($zip_code) {
        // step 1 - estimate tax based on customer provided zip code
        if(isset($zip_code)) {
            $this->load->model('tool/estimate_tax');
            $estimated_tax_rate = $this->{'model_tool_estimate_tax'}->getTaxRate($zip_code);
            if ($estimated_tax_rate) {
                $this->data['estimated_tax_rate'] = $estimated_tax_rate;
                die($estimated_tax_rate);
            }
            else {
                $this->data['estimated_tax_rate'] = 1;
            }
            $this->response->setOutput($this->render());
        }
    }
Then there's a model part, but it's working and communicating well with my controller so no reason to include it.
Finally I added the following under index() in product.php to catch the form variable

Code: Select all

        if(isset($this->session->get['zip_code'])) {
            $this->estimate($this->session->get['zip_code']);
        }
So the result that I'm getting is, there's a new field where I need it, but when I type in the zip into it, it redirects me to the main page with GET variables in the address bar :(

Also I'm a little clueless about how this works: $this->response->setOutput($this->render());
Can someone please explain? I slapped it into my code anyway, just in case.

New member

Posts

Joined
Wed Oct 10, 2012 1:59 am

Post by haosmark » Sat Dec 29, 2012 1:45 am

Anyone?

New member

Posts

Joined
Wed Oct 10, 2012 1:59 am
Who is online

Users browsing this forum: No registered users and 5 guests