ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Trouble with PHP and POST-request in template

March 30, 2012 10:34am

Subscribe [3]
  • #1 / Mar 30, 2012 10:34am

    Lyubov Berezina

    42 posts

    I was following the blog post about how to make an AJAX-enabled Calendar (http://keighl.com/post/expressionengine-dynamic-calendar-using-jquery/) and I faced a problem with $POST output.
    I am using Solspace calendar though but the problem seems to be that the POST parameters are being sent but ain’t being output.

    Here’s my page1, which sends POST request: http://vulichenko.ru/theater/copy (the source is here http://dl.dropbox.com/u/361607/copy.php)
    Here’s my page2, which contains PHP script and a calendar tag: http://vulichenko.ru/inc/mini (the source is here http://dl.dropbox.com/u/361607/mini.php)

    Here’s my JS:

    $(document).ready(function(){
    
        var month = 04;
        var year = 2012;
    
        render_calendar(month,year);
    
        function render_calendar(month,year) {
            $.post(
                "http://vulichenko.ru/inc/mini",
                { month : month, year : year },
                function(str) {
                    $('#mc_wrap').html(str).fadeIn();
                }
            );
        }
    
       
    });

    Here’s my php:

    <?php
    
    if (isset($_POST['month'])) :
        $month = $_POST['month'];
        $year = $_POST['year'];
    else :
        $month = date('m');
        $year = date('Y');
    endif;
    ?>


    The result is that the calendar alwasy shows the current month (not the April as in POST request)

    The problem is even if I try to just output the POST or GET requests (without any calendar tags), the output is empty (please see the screenshots:
    http://dl.dropbox.com/u/361607/Screenshots/28.png
    http://dl.dropbox.com/u/361607/Screenshots/27.png
    (ARRAY’s are the result of test tags used to test php output:

    <?php print_r($_POST);?>
    <?php print_r($_REQUEST);?>

    The PHP in inc/many template is turned on input. But it looks like PHP cannot fetch any requests (POST or GET).

    I will highly appreciate any help.
    Thank you!

  • #2 / Mar 30, 2012 11:34am

    Ian Ebden

    312 posts

    Some of this is a little over my head, but is this add-on any use? http://www.eevolution.co.uk/products/evopost

  • #3 / Mar 30, 2012 11:58am

    glenndavisgroup

    436 posts

    Try the following:

    <?php
    
    if (isset($this->EE->input->post('month'))) :
        $month = $this->EE->input->post('month');
        $year = $this->EE->input->post('year');
    else :
        $month = date('m');
        $year = date('Y');
    endif;
    ?>

    Mike

  • #4 / Mar 31, 2012 12:55am

    Lyubov Berezina

    42 posts

    Some of this is a little over my head, but is this add-on any use? http://www.eevolution.co.uk/products/evopost

    Thanks a lot but I have no form so this plugin doesn’t help me :(

  • #5 / Mar 31, 2012 12:55am

    Lyubov Berezina

    42 posts

    Try the following:

    <?php
    
    if (isset($this->EE->input->post('month'))) :
        $month = $this->EE->input->post('month');
        $year = $this->EE->input->post('year');
    else :
        $month = date('m');
        $year = date('Y');
    endif;
    ?>

    Mike

    Thanks Mike!
    Unfortunately it leads to the calendar to not render at all :(

  • #6 / Mar 31, 2012 1:14am

    Lyubov Berezina

    42 posts

    Ohh, now I’ve got it!
    Looks like I’ve dropped “index.php” from the URL for the POST 😊) It’s because I am using NSM htaccess generator, I’ve totally forgot that I still need to use the index.php in such occasions 😊)

    Although it still gives month = 4 instead of month = 04, but I guess this is not EE’s fault 😊

    Thanks everyone for your help 😊)

  • #7 / Apr 02, 2012 10:33am

    Shane Eckert

    7174 posts

    Hey Lyubov,

    I am glad to see that you figured this out! That’s awesome.

    Thanks to the rest of you who posted on this thread, great work.

    Have a great week guys.

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases