We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

IsPost | Forum

Marcus
Marcus Nov 17 '19
Hi folks is OW::getRequest()->isPost() same as $_Post???? 
Paul
Paul Nov 17 '19
No. isPost is just checking the REQUEST_METHOD and if it is a post request
Marcus
Marcus Nov 17 '19
So is $_POST ain't that right 
The Forum post is edited by Marcus Nov 17 '19
Paul
Paul Nov 17 '19
$_POST get a array of variables. 

OW::getRequest()->isPost() just a true or false

Marcus
Marcus Nov 17 '19
OK I got it now. Thanks so much. I can't use is valid post function case I'm fetching data with Ajax not using ow form. 
dave Leader
dave Nov 18 '19
Use this at the top of your php file that is called by ajax


       //only allow ajax requests 

      if( !OW::getRequest()->isAjax() ) 

      {        

         throw new Redirect404Exception();

         exit; 

       } 

 

So it means if this is NOT a ajax request then redirect to the 404exception 



The Forum post is edited by dave Nov 18 '19
Marcus
Marcus Nov 19 '19
Thanks gave I saw this statement but somehow didn't use it in stead I'm passing with each Ajax call parameter like let say controller:whatever. Then over at the ctrl class I check wheater that parameter is present in $_POST array.


if($_POST['controller']) != 'whatever') 
Ebenezer Obasi
Ebenezer Obasi Nov 27 '19
Marcus, were you able to resolve what you are working on? Why do you need to check for controller? If you are looking to work with different methods within the same class, in addition to Dave's comments, you can do the following:


//magic method to handle ajax requests

public function ajaxResponder( )

{

    //only allow ajax requests

    if ( !OW::getRequest()->isAjax() )

    {

        throw new Redirect404Exception();

        //there is no need to exit; request is already handled by another controller

        //exit();

    }


    //check if ajax function is specified

    if ( isset($_POST['ajaxFunc']) )

    {

        $callFunc = (string)$_POST['ajaxFunc'];


        //call ajax function within the class

        $result = call_user_func(array($this, $callFunc), $_POST);

    }

    else

    {

        //throw error 404 if ajax function is not specified

        throw new Redirect404Exception();

    }


    //print ajax response

    header('Content-Type: application/json');

    exit(json_encode($result));

}


//test ajax function. You can create as many function as you like and call them the same way we will call this function.

public function test()

{

    return "hello, test";

}


From you JavaScript, you can proceed to do this:


//submit request to our test function and log response

$.post('yourbestite.com

/pluginkey/controller/ajax-responder', {ajaxFunc:'test'}, function(response){

    console.log(response);

});

The Forum post is edited by Ebenezer Obasi Nov 27 '19
Borjan Shoes
Borjan Shoes Aug 11 '23
Borjan offers the best quality Women Shoes online in Pakistan. We provide wide range of women shoes in all over Pakistan at the best prices. So, grab your favorite shoes for women today and enjoy.
Qhaaf Bedding
Qhaaf Bedding Aug 16 '23
Qhaaf Bedding offers fitted bed sheets that perfectly complement your mattress. Enjoy a snug fit and premium quality with their range of options. Explore the selection at qhaaf.com for the perfect fit.
Mannat Clothing
Mannat Clothing Aug 16 '23
Embrace simplicity with Mannat Clothing's simple cotton suit design, crafted to keep you cool and stylish all day long.
Bagerz Bags
Bagerz Bags Aug 16 '23
Discover the beauty of khussa at Bagerz. Our collection features exquisite khussa online designs for girls, blending cultural heritage with contemporary fashion trends.
Panache Apparel
Panache Apparel Aug 17 '23
Panache Apparel offers a remarkable selection of western clothing in Pakistan. Shop online and experience the perfect fusion of style and comfort.
Aspire Bedding
Aspire Bedding Aug 17 '23
Discover Aspire Bedding's fitted bed sheet, combining style and functionality for a perfect fit and comfortable sleep. Elevate your bedroom with these meticulously crafted sheets.
aahnsaws
aahnsaws Sep 19 '23

<a href="https://www.chojnow.pl/">infos asas</a>

<a href="">[infos asas](https://www.chojnow.pl/)</a>

infos asas

[infos asas](https://www.chojnow.pl/)

[url=https://www.chojnow.pl/]infos asas[/url]

Dulce Lowe
Dulce Lowe Sep 22 '23
Hello! I'd like to express my appreciation to the writer of this informative site piece. Those curious about a wide selection of fun games will find this additional site very useful, and I agree with that assessment. connections game
topboosterseo
When I in the starting commented I clicked the -Notify me even as new surveys are introduced- checkbox and already whilst a comment is delivered I buy 4 emails sticking with the identical observation. Can there be thru any technique it's far feasible to do away with me from that service? Thanks! rws musket caps
HUNAINKHAN
HUNAINKHAN Mar 10
Very useful info. Hope to see more posts soon!.https://templatepart.com