GetSimple Support Forum
PROBLEM Correct way to post form data in ajax - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: PROBLEM Correct way to post form data in ajax (/showthread.php?tid=10741)



Correct way to post form data in ajax - vish93 - 2019-03-05

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.


RE: Correct way to post form data in ajax - datiswous - 2019-03-05

There's a form plugin: http://get-simple.info/extend/plugin/imforms/1121/


RE: Correct way to post form data in ajax - vish93 - 2019-03-05

(2019-03-05, 21:51:27)datiswous Wrote: 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.


RE: Correct way to post form data in ajax - Bigin - 2019-03-05

(2019-03-05, 21:59:40)vish93 Wrote: 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.


RE: Correct way to post form data in ajax - vish93 - 2019-03-05

(2019-03-05, 22:40:27)Bigin Wrote:
(2019-03-05, 21:59:40)vish93 Wrote: 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.


RE: Correct way to post form data in ajax - Bigin - 2019-03-05

https://www.tecmint.com/install-php-7-in-centos-7/


RE: Correct way to post form data in ajax - Tyblitz - 2019-03-07

@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();




RE: Correct way to post form data in ajax - vish93 - 2019-03-07

(2019-03-07, 09:26:06)Tyblitz Wrote: @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?