Jump to content

Product Selector issues


Harmen
 Share

Recommended Posts

Hi all,

 

Currently I am working on a filter for all the products in a category. So I've set up a class and built a (PW) form in it. When the user clicks on continue the form should return a processform function which sets the variable of the form in a session. Later in the file I want to read out that session and use that variable to select which products should show up and which should be hidden. So now with code examples to make it a bit more clear for you:

 

In my file I start with a class:

class classname
{
    public function ShowForm()
    {
        $form = $this->Form1();
        if ($this->input->post->submit) {
            if ($this->processForm1($form)) $this->session->redirect("./");
        }
        return $form->render();
    }

Then a form inside the class:

    protected function Form1()
    {
        $form = wire('modules')->get("InputfieldForm");
        $form->description = "Fill in the fields to find the mouse which fits your wishes";
        $form->label = "Mouse Selector";
        $form->action = "./";
        $form->method = 'post';

        $f = wire('modules')->get("InputfieldRadios");
        $f->name = "Hand";
        $f->label = "label";
        $f->addOption(1, "1");
        $f->addOption(2, "2");
        $form->add($f);

        $this->addSubmit($form, 'Continue');

        return $form;
    }

This function is called when the user submits:

    protected function ProcessForm1($form)
    {
        $form->processInput($this->input->post);
        $this->session->hand = (int)$form->get("Hand")->value;
    }

As you see I store the variable of the submitted form in a session. After closing the class I continue with building the page and then I want to read out that variable:

    $value = $this->session->hand;
    $content .= "Value of 'Hand': " . $value;

But when I execute this on my website I cannot see the value of the form. Have I done something wrong or how can I fix this?

Thanks in advance,

~Harmen

Link to comment
Share on other sites

7 hours ago, BitPoet said:

Properties like $this->session and $this->input are only available in Wire-derived class, so you need either use wire() syntax throughout or extend Wire in your class declaration.

Thanks, didn't know that! Changed the $this into wire(' ') and now it works!

~Harmen

Link to comment
Share on other sites

 Share

×
×
  • Create New...