...

View Full Version : What makes a site go to the page where a form is being submitted?



Flic
07-29-2007, 04:13 AM
Hi,

When a form is submitted what is it that makes the user visit the page the form is submitted to?

I have a form that doesn't do this when I want it to, because of this currently the form only works when its on the page its submitted to.

For example (its a search function I'm doing) if the site is on the search page it works fine but when its on a different page it tries to perform the function on that page instead. So it would show:
itempage.php?search=searchterm
instead of
search.php?search=searchterm

Any help much appreciated!
Thanks

matak
07-29-2007, 04:30 AM
Form action value is the where form does it's functions. If you have a form that you want to search on the same page you set your form to, you should use probably use some predefined variable like $_SERVER['php_self'] (http://php.net/reserved.variables)

CFMaBiSmAd
07-29-2007, 04:36 AM
My guess is that your <form... tag does not have an action="..." parameter at all and is submitting back to the current page instead of your search.php page.

You would need to post your code to get specific help with it.

Flic
07-29-2007, 04:33 PM
My guess is that your <form... tag does not have an action="..." parameter at all and is submitting back to the current page instead of your search.php page.

You would need to post your code to get specific help with it.

I'm not that silly :p

The form itself:

$menu[] = '<p class="mainlink">Search';
$menu[] = '<form submit="search.php">';
$menu[] = '<input type="text" name="search" size="12" />&nbsp;';
$menu[] = '<input type="submit" name="submit" value="GO!" />';
$menu[] = '</form></p>';

The search.php page:

$search = $_GET['search'];
if ($search != "") {
$sql = 'SELECT * FROM item WHERE description LIKE "%' .$search. '%" OR item_name LIKE "%' .$search. '%"OR keywords LIKE "%' .$search. '%"';
}
else{
$sql = 'SELECT * FROM item';
}
...

Flic
07-29-2007, 04:34 PM
Oh yeah, I tried what matak suggested and it didn't make a difference.

PappaJohn
07-29-2007, 05:46 PM
The <form> tag does not have an attribute named "submit".


<form submit="search.php">

it should be "action"


<form action="search.php">

CFMaBiSmAd
07-29-2007, 05:46 PM
I'm not that sillyPerhaps you should slow down and read my post and matak's post (he mentions the action parameter too.) The following line in your code has no meaning -

$menu[] = '<form submit="search.php">';

matak
07-29-2007, 06:00 PM
Also i'm not even sure how your gonna get this variable


$search = $_GET['search'];

When you didn't set the method your form works


<form action="search.php" method="GET">

I would recommend you that you use post instead of get for this example


$search = $_POST['search'];

and form


<form action="search.php" method="POST">

CFMaBiSmAd
07-29-2007, 06:32 PM
Actually, the default method is GET if one is not specified.

I was going to post the link to the w3schools html form section, but their web page is not responding at the current time and the OP should be able to lookup the proper syntax for a form. Got enough of it to post - http://w3schools.com/html/html_forms.asp

matak
07-29-2007, 06:50 PM
Actually, the default method is GET if one is not specified.

oh, ok. :)

Yes, i tried to reach w3schools yesterday, and i couldn't see their pages. Who knows, maybe their redesigning.

Btw this code works..


<form action="">
<input type="text" name="search">
<input type="submit">
</form>

<?php

@$search = $_GET['search'];

if ($search != ""){
echo $search;
}
else {
echo "Please search something";
}
?>

Flic
07-30-2007, 12:12 AM
Oh Gawd!

I did not see that! :(

This is why fresh eyes spot somethings that others mightn't!

Thanks guys!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum