Twnzl
Twnzl

Reputation: 93

Dynamic iframe content with $_POST

PHP has always been kind of a problem for me. Normally I find my way with searching and trial and error, but this time I can't figure it out.

I'm currently working on a project where people can order services online. The ordering module is on a different domain which we frame using iframe. All the rest of the content is hosted on or own domain. When people browse through our services they can click a link where they order said service online. They are being lead to a page with a dynamic iFrame. The iFrame looks like this:

<div id="outerFrame">
			<iframe id="innerframe" src="<?php echo $_POST['res']; ?>"   
            name="reserveer" frameborder="0"></iframe>    
</div>

The button that leads them there looks like this:

<form method="post" action="iframepage.php">
<input type="hidden" name="res" value="http://requestedservice.com" />
<input type="submit" value="Order now"/>
</form>

And this works pretty great! The only problem is when people go to the iframe page, the page (or frame) is empty. I would like for the users to see a standard iframe src if they didn't go to the page with a "Order now" button. So I was trying to get something like this (and tried a lot of different approaches in the meantime):

<?php
if ($_POST) {
	$resUrl =  "echo $_POST['res']";	
} else {
	$resUrl	= "http://standardframecontent.com";
}
?>

Where the frame now echos $resUrl.

Like I said, I tried a lot of different approaches. This is the first time I asked help online myself which means I'm pretty desperate.

Upvotes: 0

Views: 463

Answers (2)

S.Pols
S.Pols

Reputation: 3434

Try this:

<iframe id="innerframe" src="<?= (isset($_POST['res']) ? $_POST['res'] : 'http://standardframecontent.com'); ?>" name="reserveer" frameborder="0"></iframe>  

Upvotes: 2

Marco Mura
Marco Mura

Reputation: 582

Have you tried testing the post value like this?

if (isset($_POST['res'])) {
    $resUrl =  $_POST['res'];   
} else {
    $resUrl = "http://standardframecontent.com";
}


<div id="outerFrame">
    <iframe id="innerframe" src="<?php echo $resUrl; ?>"   name="reserveer" frameborder="0"></iframe>    
</div>

I test the var and then put it into a var. I print that var now, both case =)

Upvotes: 0

Related Questions