Forms 如何在iframe中显示表单输出?

Forms 如何在iframe中显示表单输出?,forms,iframe,google-search,xhtml-1.0-strict,Forms,Iframe,Google Search,Xhtml 1.0 Strict,我希望在我的网站上有一个搜索框,在我的网站上的iframe(XHTML1.0)中显示谷歌搜索我自己网站的结果 我不知道如何使用谷歌CSE,所以我试着自己动手 我有这个测试代码: <iframe name='test' id='test'></iframe> <form action='http://cnn.com' target='test'> <input type="text" name="q" size="20" maxlength="25

我希望在我的网站上有一个搜索框,在我的网站上的iframe(XHTML1.0)中显示谷歌搜索我自己网站的结果

我不知道如何使用谷歌CSE,所以我试着自己动手

我有这个测试代码:

<iframe name='test' id='test'></iframe>

<form action='http://cnn.com' target='test'> 
  <input type="text" name="q" size="20" maxlength="255" /> 
  <input type='submit' value="Search" /> 
</form> 

<form action="http://www.google.com/search">
  <input type="text" name="q" size="20" maxlength="255" /> 
  <input type="hidden" name="sitesearch" value="mysite.com" />
  <input type="submit" value="Search" />
</form>

<form action="http://www.google.com/search" target='test'>
  <input type="text" name="q" size="20" maxlength="255" /> 
  <input type="hidden" name="sitesearch" value="mysite.com" />
  <input type="submit" value="Search" />
</form>

正如预期的那样,上面的第一个表单将CNN页面加载到iframe“test”中

第二个表单工作正常,只是它在新页面中显示结果(而不是在iframe中)

当按下submit按钮时,第三个表单(与第二个表单相同,但“target”属性除外)根本不做任何事情

我做错了什么?我怎样才能让W3C验证程序满意呢


编辑:我想我差不多明白了:

<iframe name='test' id='test'></iframe>

<form method='post' action="test.php" target='test'>
  <input type="text" name="q" size="20" maxlength="255" /> 
  <input type="submit" value="Search" />
</form>

然后在test.php中执行以下操作:

<?php 
  $query = $_POST["q"];
  print file_get_contents("http://www.google.com/search?q=$query&sitesearch=mysite.com");
?>

我认为这在语法上是正确的——唯一的问题是谷歌返回了一个503错误(我认为它不想在没有付费的情况下这样做,或者其他什么)。


这是可以在test.php文件中使用的php代码,但是

记住这是针对谷歌TOS的,请不要滥用它

<?php
    $useragent = "Opera/9.80 (J2ME/MIDP; Opera Mini/4.2.14912/870; U; id) Presto/2.4.15";
    $ch = curl_init ("");
    curl_setopt ($ch, CURLOPT_URL, "http://www.google.com/search?q=".urlencode($_GET["q"])."&btnG=Search");
    curl_setopt ($ch, CURLOPT_USERAGENT, $useragent);   
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    echo $output = curl_exec ($ch);
    curl_close($ch);    
?>