X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   how to create a form and add it to a page? (https://forum.x-cart.com/showthread.php?t=72147)

cvaughan02 05-21-2015 05:40 AM

How to trigger doActionUpdate() in controller?
 
I need to add a simple form to a page that will trigger the 'update' method of the class. however, I have discovered that I can't just create a form in the template as xcart tells me the form is invalid. what do I need to do to create a simple post event? no fields, just a button that triggers the update method (doActionUpdate).


as a sidenote, does this mean that in xc5 we can't use custom forms that aren't tied to a model?? some of our clients have forms that are provided by third parties, so this might become an issue.

qualiteam 05-21-2015 08:40 AM

Re: how to create a form and add it to a page?
 
It is hard to answer you without seeing your code.

However, you should be able to create a controller class (a new "target"), get your custom form submitted to that target and process it there.

But it is recommended to process any forms by create a form class and linking it to your controller. Check XLite/View/Form directory for examples.

cvaughan02 05-21-2015 09:55 AM

Re: how to create a form and add it to a page?
 
Quote:

Originally Posted by qualiteam
It is hard to answer you without seeing your code.

However, you should be able to create a controller class (a new "target"), get your custom form submitted to that target and process it there.

But it is recommended to process any forms by create a form class and linking it to your controller. Check XLite/View/Form directory for examples.


Thanks for the reply..

yeah, I know it was a little vague. can you point me to a tutorial/doc on creating a form class? I tried searching but it just keeps bringing up stuff on how to modify the contact us form, which is not helpful.


here' some clarification:

I already have a page setup in the admin area. I want to add a form to it and have it submit to that same controller.

my main issue is that, in the admin page I created, I couldn't figure out how to create a form that would submit to the page without giving me that error. it looks like the generated forms have an xcart-form-id which i guess is what I'm missing.

btw, I did actually try just submitting my custom form to my controller. that's where I got the "this form appears to not have originated by xcart" or whatever that message says.

Roman Prisiazniuk 08-14-2015 04:43 AM

Re: how to create a form and add it to a page?
 
Quote:

Originally Posted by qualiteam
It is hard to answer you without seeing your code.

However, you should be able to create a controller class (a new "target"), get your custom form submitted to that target and process it there.


Please explain what name of the function that must process a form submit?

Quote:

Originally Posted by qualiteam
But it is recommended to process any forms by create a form class and linking it to your controller. Check XLite/View/Form directory for examples.

How to link that form to my controller? I want to add form to my module, in what directory do I must create that form?

qualiteam 08-17-2015 12:21 AM

Re: how to create a form and add it to a page?
 
Yes, you're right regarding the form id. X-Cart 5 signs most of the forms in the back-end and some of the forms in the storefront to prevent hackers from submitting malicious data in these forms.

\XLite\Controller\AController::needFormId() static method defines whether the controller class requires forms to be signed, or not. For back-end pages it always return "true", so all back-end forms are protected out of the box.

There is one more method: \XLite\Controller\AController::defineFreeFormIdAct ions(). It defines a list of controller actions that should bypass the form id checking. If you want your action to skip the form id check, you should find the controller that handles the form and add the name of the action to the list generated by this method of that controller class.


All times are GMT -8. The time now is 09:41 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.