Post form to another cms page

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Post form to another cms page

Post 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
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: Post form to another cms page

Post 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.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Post form to another cms page

Post 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.
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: Post form to another cms page

Post 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.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Post form to another cms page

Post 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.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Post form to another cms page

Post 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.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Post form to another cms page

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Post form to another cms page

Post 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
psy
Power Poster
Power Poster
Posts: 463
Joined: Sat Jan 22, 2005 11:19 am

Re: Post form to another cms page

Post 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
Post Reply

Return to “Developers Discussion”