Click to See Complete Forum and Search --> : Functions and PHP_SELF


moondance
09-08-2003, 03:55 AM
At the mo i have two seperate php files, one which logs in the user and displays their content, the second which acts as a simple search function.

I would like to combine these two scripts as seperate functions in one php file, so when the user logs in, it displays the first content, then when they submit the search form (a small box in the corner of the page), it will reload the page with the results of the search.

I have been reading about $_SERVER['PHP_SELF'] but am not sure how to use this to call the search function once the page has been reloaded.

Thanks for youe help

brendandonhue
09-08-2003, 05:36 AM
If you want a form to submit to itself, your form action would look like this
<form name="blah" method="POST" action="<?php echo $PHP_SELF ?>">

moondance
09-08-2003, 05:45 AM
I've tried doing that, and all it does is reload the page with the same initial user content - i'd like to to reload the page, but when it reloads, the content is the search results that the user entered.

So it goes something like this:
user logs in
mysql retreives users content
page displays inital user content
if user clicks on search -
reloads same page
executes search function
retreives search query results
page displays search query results instead of inital content

moondance
09-08-2003, 10:19 AM
ok i've been messing about with it, and i'm a bit confoosed. I basically copied the search.php file and pasted into a function in to the login.php file, and named the function search().

why can't i call a function from a form action eg:
<form method = "post" name = "submitform" action = "<? echo search(); ?>" >

Or maybe something along the lines of :
$_SERVER[PHP_SELF] function = Search()
so it will reload the page then execute the search function?

brendandonhue
09-08-2003, 02:31 PM
I would do it like this:

Name your Search submit button "search".
Then add this in your PHP file.

<?php
if(isset($_GET['search']))
{
//code for searching goes here
}
?>

Assuming your form uses the GET method...

moondance
09-09-2003, 09:30 AM
ok heres something strange i've discovered:

I done as you said, and even though the logic was flawless, it still wasn't working.

then i realised - i had an image for my submit button:

echo "<input type = image src = graphics/search_2.jpg name = bubba style = border: 0px;>";

So i put it as a standard button:

echo "<input type = submit name = bubba >";

And it works great, but not with an image for the submit button.

Even if i echo the statement properly as in:

echo '<input type = "image" src = "graphics/search_2.jpg" name = "bubba" style = "border: 0px;">;

A bit weird don't you think?

DaiWelsh
09-09-2003, 09:56 AM
With an image input the value passed from the form is not the same as the name of the button, I don't recall precisely, but I think you get two values for the x and y co-ordinates of where the user clicked on the image, that come through as something like buttonname.x and buttonname.y.

HTH,

Dai

moondance
09-10-2003, 04:18 AM
so does that i mean i can't use an image any more for my submit button, or is there another way around it?

brendandonhue
09-10-2003, 02:49 PM
I'm sure you can, but you might need a slightly different method to check if the form was submitted.

Kr|Z
09-11-2003, 01:18 AM
When using an image as a submit button, you get the coordinations of where you clicked on the image

<input type="image" src="..." name="name">

will return:

$name_x
$name_y