Page 1 of 1

Dynamic iframe values from form variables

Posted: Mon Dec 07, 2009 9:59 pm
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!

Re: Dynamic iframe values from form variables

Posted: Tue Dec 08, 2009 4:11 pm
by jeffimperial
Bump. anyone? :cry:

Re: Dynamic iframe values from form variables

Posted: Tue Dec 08, 2009 4:39 pm
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>';
}
?>

Re: Dynamic iframe values from form variables

Posted: Tue Dec 08, 2009 6:31 pm
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>