C5-8.2.1: How to set form action from one page to get posted by another?

Permalink
Hello,

I want to have a button on a Home page which will open a lightbox form which after pressing a submit button should post the form and load another page with the same form block and form processing results - exactly the same functionality as the Search block where you select the option to post results on another page.

So, I've added my form block on a Home page, added the same block on a Contacts page. When I press the submit on the Home page, it loads the Contacts page but without posting the form, so I just get the Contacts page with the same form values as were filled in on the Home page.

Here's my form action variable in view.php:
<?php
    $formAction = $view->url($resultTarget);
?>
    <form id="contact_form" 
        enctype="multipart/form-data" 
        action="<?php echo $formAction?>" 
        method="post" 
        accept-charset="utf-8">
...

Here's the controller.php:
public function view()
    {
        $resultsPage = null;
        $resultsPage = Page::getByPath('/contacts');
        $this->set('resultTarget', $resultsPage);
    }

What's wrong with that? Why doesn't the form get submitted/posted?

Thank you.

linuxoid
 
hutman replied on at Permalink Reply
hutman
Have you put a var_dump($_POST); in the receiving block to see if the information is getting posted but not being caught by the correct block?

Often times the block's controller will have a $bID in the submit function to only catch submissions from the current block, not blocks on other pages.
linuxoid replied on at Permalink Reply
linuxoid
Can I assume that because the form fields on the other page get filled in with the values on the home page, the form actually gets posted? On the other hand, it doesn't get processed.

How does the Search block do that? The bID will be different for blocks on different pages, won't it?
hutman replied on at Permalink Reply
hutman
Yes, you can assume that.

You will need to edit the controller of the block you are using to remove the check for the bID and add another specific value to the post that you can check for to decide if you want to process the post or not.
linuxoid replied on at Permalink Reply
linuxoid
Would you have an example or could you point to a block which does this? Thank you.
hutman replied on at Permalink Reply
hutman
If you provide your block's code we can help you, I don't know where to point you for other free resources though.