Reply
form action to different page
Old 11-14-2007, 12:57 PM form action to different page
Junior Talker

Posts: 2
Hi all,

Ive created a website using a layout which joins pages header, leftmenu, rightmenu, content and footer, together using my index.php page. I have a search form in my leftmenu, the form works correctly im just trying to display the results into my content part of the page (which is called page2.php) So i add this code at the top of my form code on the leftmenu page:

<form name="search" method="post" action="page2.php">

thinking that will insert the results from the search into the content part of the page (page2.php) but when I search for something it sends the browser to www.indie-design.co.uk/page2.php, instead of says on the main page and just inserting the results into the content part. Any ideas how I can do this?

Hope this makes sense,

Thanks
key_uk is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 11-14-2007, 01:40 PM Re: form action to different page
Foundationflash's Avatar
Ultra Talker

Posts: 411
Name: Harry Burt
Location: Colchester, Essex, England
That bit of HTML is designed to do that - and possibly how you want to be achieving your effect. The easiest way of doing this as I see it is to:
1) Create a page results.php or similar,
2) On that page, instead of including/requiring the content, echo the results of the search in its place (not forgetting any divs that ought to ienclose the content etc)
3) Change it to <form name="search" method="post" action="results.php">

It's hard to know exactly what system you are using of gathering search results, but you want something along those lines. If you are set on staying on index.php, change the line that looks a little like this at a guess :
PHP Code:
include_once("page2.php");
//or 
require_once("page2.php"); 
to:

PHP Code:
if($_POST){
echo 
getResults();//or however you inted to get your results
}else{
include_once(
"page2.php"); //or similar

Keeping the

<form name="search" method="post" action="index.php">

Hope that lot helps.
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 11-14-2007, 03:30 PM Re: form action to different page
Junior Talker

Posts: 2
Quote:
Originally Posted by Foundationflash View Post
That bit of HTML is designed to do that - and possibly how you want to be achieving your effect. The easiest way of doing this as I see it is to:
1) Create a page results.php or similar,
2) On that page, instead of including/requiring the content, echo the results of the search in its place (not forgetting any divs that ought to ienclose the content etc)
3) Change it to <form name="search" method="post" action="results.php">

I think I have done what you have said correctly, in my leftmenu page I have the form:

<form name="search" method="post" action="page2.php">
Search for: <input type="text" name="find" /> in
<Select NAME="field">
<Option VALUE="cd_title">CD Title</option>
<Option VALUE="cd_artist">CD Artist</option>
</Select>
<input type="hidden" name="searching" value="yes" />
<input type="submit" name="search" value="Search" />
</form>



Now I put the code to echo the results to my page2.php (contents)



<?
//This is only displayed if they have submitted the form
if ($searching =="yes")
{
echo "<h2>Results</h2><p>";
//If they did not enter a search term we give them an error
if ($find == "")
{
echo "<p>You forgot to enter a search term";
exit;
}
// Otherwise we connect to our Database
mysql_connect("localhost", "indiedesiuk", "pokemons") or die(mysql_error());
mysql_select_db("indiedesiuk") or die(mysql_error());
// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);
//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM cds WHERE upper($field) LIKE'%$find%'");
//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['cd_title'];
echo " ";
echo $result['cd_artist'];
echo "<br>";
echo "<br>";
}
//This counts the number or results - and if there wasn't any it gives them a little message explaining that
$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query<br><br>";
}
//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
}
?>

But still when I search for something the browser still sends me to http://www.indie-design.co.uk/page2.php instead of putting the results in the page2.php which is on the main page next to the leftmenu page.

and this is my index.php which links all of my pages together

</head>
<body>
<div id="maincontainer">
<div id="topsection"><?php include("http://www.indie-design.co.uk/topsection.html"); ?></div>
<div id="contentwrapper"><?php include("http://www.indie-design.co.uk/page2.php"); ?></div>
<div id="leftcolumn"><?php include("http://www.indie-design.co.uk/leftcolumn.html"); ?></div>
<div id="rightcolumn"><?php include("http://www.indie-design.co.uk/rightcolumn.html"); ?></div>
<div id="footer"><?php include("http://www.indie-design.co.uk/footer.html"); ?></div>
</div>
</body>
</html>
key_uk is offline
Reply With Quote
View Public Profile
 
Old 11-14-2007, 03:58 PM Re: form action to different page
Foundationflash's Avatar
Ultra Talker

Posts: 411
Name: Harry Burt
Location: Colchester, Essex, England
I think then that you can just change:
<form name="search" method="post" action="page2.php">
to:
<form name="search" method="post">
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Reply     « Reply to form action to different page
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12991 seconds with 12 queries