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.

Simple form and output template won't return data

December 06, 2011 4:37pm

Subscribe [1]
  • #1 / Dec 06, 2011 4:37pm

    t1media

    1 posts

    I have some basic HTML forms that are part of a template.

    I am trying to access the data being entered using php superglobal $_POST within the results template but nothing is showing up.

    For example…
    in one template, as a test, I have this simple form that passes some data to a results page when submit:

    <form action="{path=test/actions}" method="post">
     <input type="hidden" name="title" value="testing post" />
            <input type="submit" value="submit val" />
    </form>

    In the “actions” result page I am outputing $_POST within php tag and I can’t get any meaningful output.

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

    I also used to be able to access global input like this by using CI function:

    <?php
    echo $this->EE->input->post('title');
    ?>

    But this doesn’t work for me either now.
    I get PHP error message:

    Message: Undefined index: title

    .

    What is going on?

    I recently upgraded to latest version of EE… so I tried uninstalling safecracker module since I thought maybe it was hijacking the form or posted vars somehow but that made no difference.

    I am using EE v2.3.1 - Build: date 20111017. LAMP server config - PHP Version 5.3.6

    Anyone have any ideas?

  • #2 / Dec 07, 2011 1:12am

    t1media

    1 posts

    Well, I wasted a bunch of time troubleshooting a very simple issue in the end.

    I have mod_rewrite being used to remove the index.php page from the URL string.

    Instead of using {path} tag in form action and I instead reference the full path directly as so…

    <form action="/index.php/test/actions"  ...

    —it works just fine.

    Even though I thought I was passing form $_POST vars directly to the actions template on the next page load—that must not be true.

    I assume the mod_rewrite acts here as more of a page forwarder… so the POST vars are long gone by the time the actual resulting page (now 2 steps removed) is loaded.

    At least that’s my guess at this point.

    Hope this post can help someone else save a little time and frustration.

     

     

  • #3 / Dec 07, 2011 3:27pm

    Kevin Smith

    4784 posts

    Hmm, that’s odd, t1media. Are you using the index.php removal technique described in the docs? If so, the path variable should still work fine in this particular case. If you look at the HTML output of the difference between using the part variable and the solution you presented above, what’s the difference?

  • #4 / Jul 08, 2012 2:52pm

    AlteredState

    57 posts

    Hi, I also experienced the same thing.
    Got totally frustrated by no POST variables showing. None of the Add-ons returned any POST data and seemed to confirm that the POST data was being ‘lost’ before it could be accessed by the recipient output template.

    I’m removing the index.php using NSM .htaccess generator default template.

    Adding the index.php into the action url solved the issue.

    This must be something to do with the way EE is handling the action url - maybe verifying it by reference to ‘index.php’?

    It would be very helpful to know…

    Steve

     

     

  • #5 / Jul 10, 2012 12:20pm

    Dan Decker

    7338 posts

    Hi Steve,

    If you are removing index.php with NSM .htaccess Generator, and disabling that solves your problem, can I ask you to try the officially supported method?

    <IfModule mod_rewrite.c>
            RewriteEngine On
    
            # Removes index.php
            RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ /index.php/$1 [L]
    
            # If 404s, "No Input File" or every URL returns the same thing
            # make it /index.php?/$1 above (add the question mark)
    </IfModule>

    Much cleaner, and simpler than any of the generators out there and is the only way EL supports the removal of index.php in ExpressionEngine.

    Cheers,

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

ExpressionEngine News!

#eecms, #events, #releases