I want a search box on my website that displays the result of a Google search of my own site in an iframe on my site (XHTML 1.0 Strict).
I wasn't able to figure out how to use Google CSE, so I'm trying to roll my own.
I have this test code:
<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>
As expected, the first form above loads the CNN page into the iframe "test".
The second form works fine except that it displays the result in a new page (instead of inside the iframe).
The third form (same as the 2nd except for the 'target' attribute) doesn't do anything at all when the submit button is pushed.
What am I doing wrong? And how can I make the W3C Validator happy with this?
Edit: I think I've almost got it:
<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>
Then this in test.php:
<?php
$query = $_POST["q"];
print file_get_contents("http://www.google.com/search?q=$query&sitesearch=mysite.com");
?>
I think this is syntactically correct - the only problem is that Google gives back a 503 error (I think it doesn't want to do this without being paid, or something).
This is the php code that will work in your test.php file but
Remember THIS IS AGAINST GOOGLE TOS please do not abuse it