Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PROBLEM Correct way to post form data in ajax
#1
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.
Reply
#2
There's a form plugin: http://get-simple.info/extend/plugin/imforms/1121/
Reply
#3
(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.
Reply
#4
(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.
Reply
#5
(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.
Reply
#6
https://www.tecmint.com/install-php-7-in-centos-7/
Reply
#7
@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();

Reply
#8
(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?
Reply




Users browsing this thread: 1 Guest(s)