How To Dispatch To A Mode In A .post Controller

Hello guys.

I have a products.post.php controller and in this file I have a mode called "print".

I want to create a form and show a button that takes the data my customer types into the fields and then print them into a pdf for example.

I have created the form, I can show the button but my dispatch returns a 404 page.

Here what I have:


Yes No

Class 1

Button1, redirects to a 404 page.

Button2, works ok but it does not take on account the form data.

How can I pass the data from the selections I have plus use the method named "print" that exists in products.post.php?

It's kinda messed up I think, if you want more explanations please ask me.

Thanks in advance.

First solution should work. Try to add the following code to the beginning of the controller

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if ($mode == 'print') {
        fn_print_die($_REQUEST);
    }
}

I would suggest you do this in the my_changes addon (or create a separate addon). Steps would be:

Create/update the addon (using my_changes as the example) to have a controllers/my_changes.php file with something like:

switch($mode) {
  case 'print':
     if( $_SERVER['REQUEST_METHOD'] == 'POST') {
       $my_options = $_REQUEST;
       // process your form data here from $my_options
       fn_set_notification('N', __("notice"), "Your message here for processed data");
       $url = "your redirect URL";
       fn_redirect(fn_url($url));
    }
    // A GET request would come here and ultimately load the the views/print.tpl file
    return array(CONTROLLER_STATUS_OK);
}

Then you need to put your form in design/themes/[YOUR THEME]/templates/addons/my_changes/views/my_changes/print.tpl.

If you want the form somewhere else (like embedded in some other page) then just never call my_changes.print via a GET request and only reference it from your form as a POST request.