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

Handling Variables Through multiple pages/iFrames

Development and Programming

a la mode's avatar
a la mode
168 posts
15 years ago
a la mode's avatar a la mode

I have a page that holds a “preview” pane. The preview needs to update per the users’ selections. User selections are being made via jQuery dialog modals. I trigger actions per the selections made. The problem I have is figuring out how to handle the data changes through the iframe. I would like to handle everything through embeded templates, but because of the resets and other css on the primary page, the inner content renders incorrectly when loaded. (Inner content is email)

Has anyone had luck with passing variables through to iframes? Every time I feel like I have the solution, I begin to implement to realize I hit a wall.

I have tried the following:

– Catching the template and the entry id in js variables and passing them through an ajax request…

//    Load the results via ajax
$.ajax({
    type: "POST",
    url: "/php/index",
    data: "template="+selected_template+"&entryID;="+current_id+"",
    success: function(data){
        $("#email_body").html(data);
    }
});

Then trying to pass data back as an iframe in the php index template…

<?php
    $template = $_POST['template'];
    $entry = $_POST['entryID'];
?>
<iframe id="template_loader" name="template_loader" src="{sandbox}/index.php?/Email_Templates/<?php echo $template ?>" width="100%" height="100%" allowtransparency="true" scrolling="no"></iframe>

… but I don’t know how to handle the entryID portion.

Any ideas? Am I making this harder than it needs to be?

       
a la mode's avatar
a la mode
168 posts
15 years ago
a la mode's avatar a la mode

OK… I’m an idiot. (forgive me for I come from asp…)

QueryStrings == BAD w/ EE… lol

so I simplified by using session vars instead…

//    Load new iFrame per selection via ajax
$.ajax({
    type: "POST",
    url: "/php/Session_Write",
    data: "template="+selected_template+"&entryID;="+current_id+"",
    success: function(data){
        $("#template_loader").attr("src", "{sandbox}/index.php?/php/index/");
    }
});

…where “#template_loader” is the iFrame and “Session_Write” is a template like:

<?php
    $template = $_POST['template'];
    $entry = $_POST['entryID'];
    
    session_start(); 
    $_SESSION['template'] = $template;
    $_SESSION['entry'] = $entry;
?>

…Then my php/index file being loaded into the iFrame simply reads the session variables

<?php
    session_start();  
    $template = $_SESSION['template'];
    $entry = $_SESSION['entry'];
?>
{embed="Email_Templates/<?php echo $template ?>" entry_id="<?php echo $entry ?>" dynamic="off" disable="trackbacks"}

This allows me to keep from multiple page loads and redirects so the user gets instant gratification…

Hopefully that helps someone else out. If there is a better way or any suggestions, I am always open. 😊

       

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.