GetSimple Support Forum

Full Version: Correct way to post form data in ajax
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear community,

Currently I have a PHP file in the theme folder where I post my form data to for processing. This seems to be incorrect to me so I am wondering if a kind soul could inform me of the "correct" way to handle form post data in getsimple CMS?

I am going then via plugin display the data in the backend.
(2019-03-05, 21:51:27)datiswous Wrote: [ rel="nofollow" -> ]There's a form plugin: http://get-simple.info/extend/plugin/imforms/1121/

Came across it yesterday but not really suitable for what I am after. You also have to run at least PHP 5.6.0 on your server.

I have in a new theme.php file created my form that I will display. Then collect the responses and show in backend admin plugin page.

I just need to figure what is the correct way in getSimpleCMS to handle ajax posts, as a php file in my theme folder doesn't seem the best solution.
(2019-03-05, 21:59:40)vish93 Wrote: [ rel="nofollow" -> ]Came across it yesterday but not really suitable for what I am after. You also have to run at least PHP 5.6.0 on your server.

- Yeah, but only because you don't really have a clue how that works ;-)

You can use ItemManager to do this.
It can process and save the data coming from your form for you.

PS. ItemManager requires at least PHP 5.6.0, you are right.
(2019-03-05, 22:40:27)Bigin Wrote: [ rel="nofollow" -> ]
(2019-03-05, 21:59:40)vish93 Wrote: [ rel="nofollow" -> ]Came across it yesterday but not really suitable for what I am after. You also have to run at least PHP 5.6.0 on your server.

- Yeah, but only because you don't really have a clue how that works ;-)

You can use ItemManager to do this.
It can process and save the data coming from your form for you.

PS. ItemManager requires at least PHP 5.6.0, you are right.

Unfortunately CentosOS does only support 5.4 in official repo.
@vish93

If you are going to do it with your own plugin (which would indeed be better than in the theme folder),
GS provides some functions for handling AJAX together with auth (requestIsAjax, get_cookie, and check_nonce)

I do AJAX saving in my plugin Components Extended (see my signature below), you can look at the code for inspiration, see this excerpt for example:

PHP Code:
$global $USR;
if (
requestIsAjax()) { 

 
 // protect against CSRF, basic check
 
 if (!isset($USR) || $USR != get_cookie('GS_ADMIN_USERNAME')) 
 
   die();

 
 // only continue if the request comes from the same domain & nonces match
 
 if (empty($_GET['nonce']) || !check_nonce($_GET['nonce'], 'components_ext_action''components_ext.php'))
 
   die();

(2019-03-07, 09:26:06)Tyblitz Wrote: [ rel="nofollow" -> ]@vish93

If you are going to do it with your own plugin (which would indeed be better than in the theme folder),
GS provides some functions for handling AJAX together with auth  (requestIsAjax, get_cookie, and check_nonce)

I do AJAX saving in my plugin Components Extended (see my signature below), you can look at the code for inspiration, see this excerpt for example:

PHP Code:
$global $USR;
if (
requestIsAjax()) { 

 
 // protect against CSRF, basic check
 
 if (!isset($USR) || $USR != get_cookie('GS_ADMIN_USERNAME')) 
 
   die();

 
 // only continue if the request comes from the same domain & nonces match
 
 if (empty($_GET['nonce']) || !check_nonce($_GET['nonce'], 'components_ext_action''components_ext.php'))
 
   die();


Thank you ever so for the response. I am going to use the plugin for storing/keeping track of responses from the form. For the ajax post where should I be point the url to?