Page 1 of 1

Form integration in UDT

Posted: Thu Nov 05, 2015 9:16 am
by chunteler
Hi,

I'm using CMSMS 1.12.
I'm busy developing a module for a customer.
I created a UDT that can be called in the content of a page to display specific info about a product.
From the UDT I call a form so that the product can be ordered. Everything has to happen within the UDT.
The form I created is not made with FormBuilder. I programmed it myself and called it action.orderform.php. It's using orderform.tpl as template.
Calling the form directly on a page works fine. It gets processed on submit.
Calling the form from the UDT and displaying it via the UDT on the page, I keep being sent back to the Home page on submit.
What did I do wrong?
I hope someone can help me.
Thanks in advance.

Re: Form integration in UDT

Posted: Thu Nov 05, 2015 4:47 pm
by calguy1000
Please read the module writing tutorial (Advanced section on the docs site).

If you have a module like this, that you are authoring then you should almost never need to use UDT's like this. You may just need to create more actions.

It may be different if you are trying to work with somebody else's module... but if it's your own module, it shouldn't be necessary.

Also, your form handling can be done in the same action/controller that outputs the form, it's cleaner and simpler this way.

Also, it is bad form to output HTML like that from within PHP code. That is what smarty templates are for. Your PHP code should just provide data to smarty, that you then format within the template.

Re: Form integration in UDT

Posted: Thu Nov 05, 2015 5:29 pm
by Jeff
chunteler wrote: Calling the form from the UDT and displaying it via the UDT on the page, I keep being sent back to the Home page on submit.
When you call a module action from a page you are passing the proper variables to the action for the page. But by default those aren't passed to the UDT and then not passed when calling your action.

I agree with Calguy1000, UDT are for small pieces of code and it sounds like you have passed that point.

Re: Form integration in UDT

Posted: Mon Nov 09, 2015 2:25 pm
by chunteler
Thanks Jeff and Calguy1000!
I'm new to CMSMS and I thought I had to use a UDT because the customer wanted me to use a tag. Now I'm reading your reactions I realize I can do that in a much easier way with actions.
Thanks also for your feedback on Smarty.