Dynamic iframe values from form variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jeffimperial
Forum Newbie
Posts: 13
Joined: Sun Feb 01, 2009 9:54 pm

Dynamic iframe values from form variables

Post by jeffimperial »

Okay, I'm not sure if this is doable, but I'd like to ask you guys here.

I want to provide visitors a way to search for and make Google Trends searches on my site (without having to go to http://google.com.trends/). My idea is that if I made a PHP form on http://mydomain.com/page1.php where there are textboxes to enter keywords into, the values for those textboxes can be retrieved as $variables, which then can be somehow forwarded to http://mydomain.com/page2.php where a Google Trends gadget lives, and the code can be modified on-the-fly with the passed variables from the form:

Code: Select all

<iframe src="http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/trends_gadget.xml&source=imag&up_is_init=true&up_cur_term=$textbox1,+$textbox2,+$textbox3,+$textbox4&up_date=mtd&up_region=US" style="border:1px solid #ccc; padding:10px;" width="330" height="250" frameborder="0" scrolling="no"></iframe>
I'm not sure if this makes any sense to you.. So can this be done? Thanks heaps!
jeffimperial
Forum Newbie
Posts: 13
Joined: Sun Feb 01, 2009 9:54 pm

Re: Dynamic iframe values from form variables

Post by jeffimperial »

Bump. anyone? :cry:
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Dynamic iframe values from form variables

Post by AbraCadaver »

Bump, yes. Something like (just an example):

Code: Select all

<?php
//this file is named trends.php
if(!isset($_POST['submit'])) {
    echo '<form method="post" action="trends.php">
            <input type="text" name="textbox1">
            etc....
            <input type="submit" name="submit">
            </form>';
} else {
    echo '<iframe src="http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/trends_gadget.xml&source=imag&up_is_init=true&up_cur_term=' . $_POST['textbox1'] . ',+' . $_POST['textbox2'] . ',+' . $_POST['textbox3'] . ',+' . $_POST['textbox4'] . '&up_date=mtd&up_region=US" style="border:1px solid #ccc; padding:10px;" width="330" height="250" frameborder="0" scrolling="no"></iframe>';
}
?>
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
jeffimperial
Forum Newbie
Posts: 13
Joined: Sun Feb 01, 2009 9:54 pm

Re: Dynamic iframe values from form variables

Post by jeffimperial »

AbraCadaver wrote:Bump, yes. Something like (just an example):

Code: Select all

<?php
//this file is named trends.php
if(!isset($_POST['submit'])) {
    echo '<form method="post" action="trends.php">
            <input type="text" name="textbox1">
            etc....
            <input type="submit" name="submit">
            </form>';
} else {
    echo '<iframe src="http://www.gmodules.com/ig/ifr?url=http://www.google.com/ig/modules/trends_gadget.xml&source=imag&up_is_init=true&up_cur_term=' . $_POST['textbox1'] . ',+' . $_POST['textbox2'] . ',+' . $_POST['textbox3'] . ',+' . $_POST['textbox4'] . '&up_date=mtd&up_region=US" style="border:1px solid #ccc; padding:10px;" width="330" height="250" frameborder="0" scrolling="no"></iframe>';
}
?>
Thanks AbraCadaver! Here's what I came up with:

On the form page:

Code: Select all

<form method="post" action="trends.php">
<label style="color: #1F85E7;">Keyword 1:<input type="text" name="keyword1"/></label>
<label style="color: #1F85E7;">Keyword 2:<input type="text" name="keyword2"/></label>
<label style="color: #1F85E7;">Keyword 3:<input type="text" name="keyword3"/></label>
<label>
    <input type="submit" name="submit" id="submit" value="Submit" />
</label>
</form>
Then on trends.php

Code: Select all

<?php
//retrieve keywords from previous form
$keyword1 = $_REQUEST['keyword1'] ; 
$keyword2 = $_REQUEST['keyword2'] ; 
$keyword3 = $_REQUEST['keyword3'] ; 
 
// make the source for iframe based on keywords from form
$src = " http://www.gmodules.com/ig/ifr?url=http ... +$keyword3" ;
 
?>
 
<iframe src=<?php print $src; ?> style="border:1px solid #ccc; padding:10px;" width="600" height="250" frameborder="0" scrolling="no"></iframe>
Post Reply