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?
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. 😊
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.