Page 1 of 1

Post form to another cms page

Posted: Sun Mar 03, 2013 3:02 pm
by nervino
Hello, is it possible to have a form post to another cms page?

I have 2 cmsms pages: page1 and page2

In page2 I put a module that creates a form in this way:

Code: Select all

$smarty->assign('formstart', CreateFrontEndFormStart($id,'16','default');
where '16' is the id of page1.
$smarty->assign('myvalue', $this->CreateInputHidden($id, 'myvalue', '11475' ));
When I submit the form from page2, page1 is loaded and displayed but 'myvalue' parameter is NOT passed.

What am I doing wrong?

thanks

Re: Post form to another cms page

Posted: Mon Mar 04, 2013 12:35 pm
by psy
Yes it is possible to submit a form post to another page, cms or otherwise. You're probably doing nothing wrong. :)

Try using smarty replace on the template tag to change the form action to force it to go to page 2.

You can do this by assigning the form to a template var then using something like {$myform|replace:'action="the-page-1-form-submit":"the-page2-form-submit"}

Check out http://www.smarty.net/docs/en/language. ... eplace.tpl for more info.

Re: Post form to another cms page

Posted: Mon Mar 04, 2013 3:02 pm
by nervino
Hi psy, thank you for replying.

I don't need to change the form action, that I can do when creating the form in my module.

I have 2 cmsms pages. For example, in my site navigation menu I have:
- Home page
- Page1
- Page2

I want to display the form (calling my module) in Page2, and display the submitted values in Page1. To achieve this, I tried to change the $returnid parameter of the form, setting the one of Page1 ("16") . When I submit the form, the cms active page changes from Page2 to Page1 BUT the form's values are not passed to Page1.

Re: Post form to another cms page

Posted: Mon Mar 04, 2013 3:24 pm
by psy
OK, let's try another tack. Does the module have an 'Edit' event, ie Extensions->Event Manager?

If so, you could capture the form results from the form submitted on Page 2 and pass them to Page 1 via a UDT (or on whatever page you need to see the submitted values).

Thirdly but not really recommended is to use js or session vars to pass the submitted values from Page 2 to Page 1. I'd try the Event Manager UDT option first though.

Re: Post form to another cms page

Posted: Tue Mar 05, 2013 11:10 am
by nervino
Well, hence I infer from your answers that there isn't a way to pass form variables between pages recalling the same module, without using UDTs etc.
So, I'll make my form stay in the same page, toggling it with jquery.

Thank you very much.

Re: Post form to another cms page

Posted: Tue Mar 05, 2013 12:41 pm
by nervino
I've just found a way to partially solve my problem using Smarty.
In the tag with which I recall my module in Page1, I put:
{cms_module module="MyModule" myvar=$smarty.post.m61137myvar}

In this way $params['myvar'] gets the correct value from Page2.

It's not a very clean way to do it, because I have to specify by hand the form suffix 'm61137' and I don't like it.
If anyone has got another better solution, please post it.

Re: Post form to another cms page

Posted: Tue Mar 05, 2013 3:31 pm
by calguy1000
if you are calling your module on page A, and wish the form to be handled on page B it's simple.

a: Make sure you are not setting the 'inline' parameter of CreateFormStart
b: Set the returnid in the CreateFormStart to the destination page.

You do not need to call your module on the destination page.

This however, is usually not good practice. (though I have done it). Better practice is to handle the form on the same page, and then redirect to the destination page.

Re: Post form to another cms page

Posted: Wed Mar 06, 2013 7:24 pm
by nervino
I did as you suggested, but I can't get the values in destination page, where I need to load the same module that, in my intention, has to grab the posted values.
I'll give it a try with a clean test module, just for study as I agree with you in handling the form in the same page.

Thanks

Re: Post form to another cms page

Posted: Thu Mar 07, 2013 9:09 am
by psy
Have you checked out http://forum.cmsmadesimple.org/viewtopi ... ce#p259639 for info on smarty replace?

Another thing worth looking at when the return id is Page 1, is what is in $smarty.post? See http://www.smarty.net/docsv2/en/languag ... smarty.tpl