We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Using $EXT->last_call question

Development and Programming

bhggraphicdesign's avatar
bhggraphicdesign
52 posts
17 years ago
bhggraphicdesign's avatar bhggraphicdesign

I don’t understand how I would do that and get the data I need. The post data from my entry form is not available by the time the redirect page is hit. How can I get it? Can you give me a brief example, please?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Your session hook will have access to the POST data long before the system processes and redirects. To see it in action, add a session hook extension, and var_dump($_POST);exit; in your method. Only after your method is finished will the system process the submitted entry.

       
bhggraphicdesign's avatar
bhggraphicdesign
52 posts
17 years ago
bhggraphicdesign's avatar bhggraphicdesign

Using the “sessions_end” hook in an extension and adding a var_dump to the main method lets me see the post data (including what I want) in the redirect page. But this doesn’t let me use it.

Putting code in the extension, I’ve tried setting a custom session. Doesn’t work. session_start() kills the page and $_SESSION[‘vid’] doesn’t get the information. I don’t want to hack into EE’s session class to add a new property, which doesn’t work either.

Setting a cookie with php “setcookie(‘vid’, $_POST[‘vid’]) seems to set a cookie (I can see it in the “View Cookies CS” FF extension), but I can’t read it with either js or php. And if I add a conditional (if (isset($_POST[‘vid’]))), it doesn’t set the cookie at all.

I’m obviously not seeing something. How do you access the info?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Why do you need to set a cookie or add it to the session information? And it sounds like you are having general coding issues with both of those methods, as there’s nothing in ExpressionEngine that would interfere. But you have it right at that moment in $_POST[‘vid’], so you can use it right then.

       
bhggraphicdesign's avatar
bhggraphicdesign
52 posts
17 years ago
bhggraphicdesign's avatar bhggraphicdesign

I’m really not getting this.

My aim is to take user data from an SAEF that is written to a hidden input by js on submit and use it as a parameter to call an outside function from the SAEF’s return page. The outside function itself may take over a minute to complete, so I don’t want it to be called from the SAEF itself for usability reasons. (I’ll probably make it an Ajax call.)

The way I understand it is that an extension that uses the “sessions_end” hook seemingly has access to all the post data that ever was. And, because it uses that hook, it is called on every page load.

So do I have to put the call to the external function I want to use in the extension? If so, how do I know which page has loaded? $FNS->fetch_current_uri() “crashes” the page. And “if(isset($_POST[‘vid’])) always seems to be false, even though it will show up in the var_dump. Can I then unset $_POST[‘vid’] so the function is not called on later page loads?

Or do I not use an extension at all and try to call the hook from code on the redirect page?

Thanks for your patience.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Have you considered hiring someone to write the extension for you? We’re more than happy to help third party developers with explaining how EE’s API works and what’s possible, but I cannot give you the level of general PHP assistance that you need.

       
bhggraphicdesign's avatar
bhggraphicdesign
52 posts
17 years ago
bhggraphicdesign's avatar bhggraphicdesign

Not really. Plus I need it to work now.

I do have a fallback (run the function from a cron), but I would prefer to avoid that at this point.

Besides, it would be nice to understand what’s going on. Keeps me from hacking the core and/or coding things from scratch outside EE whenever I need some additional functionality.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

The problems you are having don’t sound indicative of an issue with ExpressionEngine, though. Not being able to read/set cookies, pages “crashing” when you attempt to use a method that does nothing but return a string, understanding isset(), PHP’s $_POST array, etc. As before, if you provide fully reproducible code samples, we, or community members can often help you identify problem areas or potential gotchas, but we cannot troubleshoot all of your PHP issues.

       
bhggraphicdesign's avatar
bhggraphicdesign
52 posts
17 years ago
bhggraphicdesign's avatar bhggraphicdesign

Well, I found a way to do what I want. Outside of EE, using only my extension that adds “onsubmit”. It might even be a better way for my needs.

But I would still like to know why the extension doesn’t work. The extension calls the “sessions_end” hook. It’s only got one method outside of the standard ones EE needs to call it, etc. If its main method is:

function sessTest($var) {
    var_dump($_POST);
}

I get “array empty” on the SAEF page onload. I get the expected results, including data from my hidden input that contains the filename I want, when I get to the return page. So I know that the $_POST variable has, at some point, contained the data I need.

If I change the extension’s main method to:

function sessTest($var) {
    if (isset($_POST['vid'])) {
        var_dump($_POST);
    }
}

var_dump never (visibly) fires. But the data must have been there at some point, because it showed up earlier.

So seeing that I have access to the session data through the main method’s single parameter, I added another parameter to the $SESS variable in core.session.php (‘vid’ => ”). Then I changed the main method to:

function sessTest($var) {
    $var->userdata['vid'] = $_POST['vid'];
}

hoping to catch the data this way. When I check $SESS on the return page, ‘vid’ is null, showing me that there must have been an intermediate post somewhere, as I suspected. So I add the conditional again so that the session will only be changed when the variable is available:

function sessTest($var) {
    if (isset($_POST['vid'])) {
        $var->userdata['vid'] = $_POST['vid'];
    }
}

But now when I check $SESS in my return page, ‘vid’ = ”, its default value.

So what’s up with that?

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Try using exit; after your debugging output. If you’re letting program execution continue, then the processing and redirect will happen so that no output is sent to the browser. POST data is not maintained on a redirect, so the landing page after the form submission is processed will no longer contain your field or data.

       
bhggraphicdesign's avatar
bhggraphicdesign
52 posts
17 years ago
bhggraphicdesign's avatar bhggraphicdesign

I figured that it was a redirect, that’s why I tried to add the data to the existing session.

Put the “exit;” where? There’s only three possibilities: SAEF, extension or landing page. And I don’t understand how stopping the page processing gains me anything as I need to have things happen on both pages.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

Could be a source of your confusion, but the Session class does not create persistent sessions across page loads, it is created and destroyed every page request. It does not equate at all with the PHP $_SESSION handling.

I’m suggesting that you put the exit; immediately after your debugging output so that you can see that it does indeed exist. What you do with it from that point is entirely up to you. You could use native PHP sessions if this is only going to run on your server and you don’t have to worry about possible changes to the SESSION environment, you could store flash data in a cookie, in the database, whatever you like so that it’s available to you on the current and future page requests.

       
bhggraphicdesign's avatar
bhggraphicdesign
52 posts
17 years ago
bhggraphicdesign's avatar bhggraphicdesign

I ended up putting the data (video filename) in a cookie on submit that I can read with JavaScript on the return page for the form. Then I use an Ajax call to pass it to a function that then passes it to a customized version of phpvideotoolkit (which calls ffmpeg, etc.) for encoding to .flv if needed.

While the video is being encoded, the user gets to watch a progressbar or something. (Haven’t really figured that part out yet.) Then the user is redirected to the page that contains his encoded video, playable with a slightly modified version of the FLV Player Plugin.

Passing the filename hinged on my extension that added the “onsubmit” event to SAEF (update attached). Thanks for your help with the last_call part. (And thanks to Mark Huot for his upload extension, which made uploading the videos possible.)

One thing I noticed, however. I cannot add a “class” attribute using the form_declaration_modify_data hook. I can see why EE might not want me to change the id, action and method, but what does it have against class, which would be useful for styling?

Edit: I’ve found that I can write a totally custom form, change the id and still have it post. But I lose the “categories” option. So is it possible to change the id on an SAEF so that I might have several forms that post to different weblogs all on the same page? Again, form_declaration_modify_data doesn’t work.

       
Derek Jones's avatar
Derek Jones
7,561 posts
17 years ago
Derek Jones's avatar Derek Jones

You can either manually set the ‘id’ in your extension code, or add ‘id’ to your $form_attrs class array and you can modify the id with a tag parameter.

       
bhggraphicdesign's avatar
bhggraphicdesign
52 posts
17 years ago
bhggraphicdesign's avatar bhggraphicdesign

Hmmm, id and action work today, maybe adding last_call helped? Class still doesn’t, but it doesn’t really matter much, now that I can change the id. Thanks. I’ve updated the extension (again).

       
1 2 3

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.