Jump to content

Search engine, results in iframe


kanala

Recommended Posts

Hi, I have a search engine (php) for my site, but I was wandering if it was possible to make the results appear inside an iframe. Here is the form for the search:

<form method="post" onsubmit="document.getElementById('page').src='search.php'"><input type="text" name="search" size="15" /> <input type="submit" style="width:25px; height:20px;" value="Go" /></form>
I'm not sure if it works yet, but am I heading in the right direction?
Link to comment
Share on other sites

Thanks, but the form doesn't seem to be able to post it. Here is the form:

<form target="ipage" method="post" onsubmit="document.getElementById('page').src='search.php'"><input type="text" name="search" size="15" /> <input type="submit" style="width:25px; height:20px;" value="Go" /></form>
And this is the search engine bit.
<?php$dbhost = "fdb1.awardspace.com:3306";$dbname = "icegifts_prod";$dbuser = "icegifts_prod";$dbpass = "....";$dblink = mysql_connect($dbhost, $dbuser, $dbpass);mysql_select_db($dbname, $dblink);$ItemName = mysql_real_escape_string($_POST['search']);$query = "SELECT * FROM products WHERE lower(Item_name) LIKE lower('%$ItemName%') ORDER BY Item_name";$result = mysql_query($query) or die(mysql_error());?><h2>Search results "<?php echo $ItemName ?>"</h2><?phpif (mysql_num_rows($result)==0){ echo "<p>No results found, please search for a keyword of the name of the product you are looking for.</p><br><br>";}while($row = mysql_fetch_array($result)){echo"<div class=\"search\"><div class=\"searchr\"><img src=\"products/".$row['Item_no'].".jpg\" width=\"116px\" height=\"116px\" class=\"searchimg\" /><img src=\"images/searchr.png\" width=\"116px\" height=\"116px\" class=\"searchbr\" /><div class=\"searchhead\">".$row['Item_name']."<span style=\"padding-left:30px; text-align:right\">£".$row['Price']."</span></div><div class=\"searchdes\">".$row['Material']."</form></div></div></div>";}?>
You see the bit where it says <?php echo $ItemName ?>, when I do the search, nothing shows up as ItemName, which probably means that it did not get posted.
Link to comment
Share on other sites

You're not actually submitting the form. Your form tag needs an "action" attribute. That's where you put the address of your php document. onsubmit lets you insert (for example) a routine for validating form fields before you finalize the submission. It is not the place for the page address.

Link to comment
Share on other sites

You're not actually submitting the form. Your form tag needs an "action" attribute. That's where you put the address of your php document. onsubmit lets you insert (for example) a routine for validating form fields before you finalize the submission. It is not the place for the page address.
So what should the action be? Because if I use search.php then it goes to the page, but I need it inside the iframe.
Link to comment
Share on other sites

That's why you need to match the target attribute of your form tag to the name attribute of your iFrame.I admit it's a little confusing just now whether to reference your form by a name or an id. Here's a snippet from one of my pages:

<form id='myForm' action='test.php' method='post' onsubmit='mySubmit(this);return false'>

It corresponds to this javascript function:

function mySubmit(F){   if ((F.userName.value == '') || (F.pw.value == '')){	  document.getElementById('warn').style.visibility = 'visible';	  setTimeout("document.getElementById('warn').style.visibility = 'hidden';",5000);   }else{		  F.submit();   }}

Link to comment
Share on other sites

That's why you need to match the target attribute of your form tag to the name attribute of your iFrame.I admit it's a little confusing just now whether to reference your form by a name or an id. Here's a snippet from one of my pages:
<form id='myForm' action='test.php' method='post' onsubmit='mySubmit(this);return false'>

It corresponds to this javascript function:

function mySubmit(F){   if ((F.userName.value == '') || (F.pw.value == '')){	  document.getElementById('warn').style.visibility = 'visible';	  setTimeout("document.getElementById('warn').style.visibility = 'hidden';",5000);   }else{		  F.submit();   }}

But does that use iframe?
Link to comment
Share on other sites

But does that use iframe?
Sorry. I forgot to include a target attribute.laugh.gif
<form id='myForm' action='test.php' method='post' onsubmit='mySubmit(this);return false' target='myIFrame'>

Link to comment
Share on other sites

I don't understand what all this is about:

if ((F.userName.value == '') || (F.pw.value == '')){ document.getElementById('warn').style.visibility = 'visible'; setTimeout("document.getElementById('warn').style.visibility = 'hidden';",5000); }else{ F.submit(); }}
Surely this still opens up a new window for the form?
Link to comment
Share on other sites

So how would I submit the search form so the results show up inside an iframe. What should I put as the action? When I put search.php (which is the page inside the iframe), it just opens up a new window.

Link to comment
Share on other sites

You make the target attribute's value the name of your iframe. E.g. if your iframe has name="searchframe" then the form has target="searchframe"

Link to comment
Share on other sites

You make the target attribute's value the name of your iframe. E.g. if your iframe has name="searchframe" then the form has target="searchframe"
No i need to know what to put in the action box. ThanksEDIT: OHH, I have solved it, I must put the full URL.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...