Page 1 of 1

$path new Dir from a Query

Posted: Tue Mar 11, 2003 3:40 pm
by meandrew
Hi All

This may sound simple but I'll give it a shot. I have a form that goes to a said file. I want to change this so that the form goes to a new Dir. The Dir being a selection from the form! Now the form is being processed before it can assign a $Dir so presumably I need to have something between the form that is sending and the Dir that I want to end up in? Am I thinking straight or do I need a long sleep :)

The form is based on a drop down that is populated from a MySQL table, which you have already seen before! :)


I am thinking that if I have this:
<form action='./TownsCityCompanies.php' method='POST' name='CompanySearch'>

and change it to
<form action='./TownsCityCompanies.php$NewDir' method='POST' name='CompanySearch'>


where $NewDir is the selection made from the drop down I am on the right track? Or I need to do what I previously said and have something process before redirection?

Andrew

Posted: Tue Mar 11, 2003 3:53 pm
by puckeye
Let me see if I understand correctly...

You want to send the user to a specific directory when he submits the form. Is that right?

That's simple.

After you check if the user selected something in your drop down menu you issue this command:

Code: Select all

<?php
Header("Location:".$file);  // Where $file is the selection from the drop down menu.
?>
You have to make sure that there's no output before you use the Header() function or else you'll have a "headers already sent" error.

Posted: Tue Mar 11, 2003 4:19 pm
by meandrew
ok I have just tried that and got a few errors, but at least you have pointed me in the right direction :) I think!

Should I be putting the

Header("Location: $county"); in the form, well I gues I know the answer to that one no becuase it just does nothing other than weird stuff and wont allow a refresh even after the file is reverted back to its original state :(

You want to send the user to a specific directory when he submits the form. Is that right? this is correct.

The form allows the user to select a county and the county selected will have its own county http://www.domain.net/county/

Not really sure about this header I can see what it is doing but not how it will select the $formvalue ?

Andrew

Posted: Tue Mar 11, 2003 5:14 pm
by bionicdonkey
have the form action set the the same page.
then when submitted it will send the value to that page so at the top you will need to do something like:

Code: Select all

if(isset($_POST['invoke'])) { //where invoke is the value of Submit
  header("Location: http://".$_SERVER['SERVER_NAME']."/".$_POST['value']);
  exit();
}

Posted: Wed Mar 12, 2003 2:30 am
by meandrew
any form of change in the behaviour of my browser is good as far as I am concerned and there is certaily change!

if I put this:

Header("Location:".$county); // Where $file is the selection from the drop down menu.

at the bottom of the page I get this error:
Warning: Cannot add header information - headers already sent by (output started at c:\program files\apache group\apache\htdocs\punterspower\county.php:47) in c:\program files\apache group\apache\htdocs\punterspower\county.php on line 177

if I put:
Header("Location:".$county); // Where $file is the selection from the drop down menu.

the weird that I have discovered and for the lifer of me cannot understand, displays the index.php whilst in the address bar says its the county.php file this is surely impossible. Anyway thats is a slight deviation.

I have checked the manual and allinfo on post is to do with file uploads!

I am beginning to think that this is not the right way for my problem?

Andrew

Posted: Wed Mar 12, 2003 4:14 am
by meandrew
I think I am following this :)

I am not having too much success however. Is my logic right of I have:

<form action='$County/index.php?County=$County' method='POST' name='CompanySearch'>

The form should post to the selcted County DIR if using the header:<?php
Header("Location:".$County); // Where $file is the selection from the drop down menu.
?>

I'm asking because this just isn't working at all :(

Andrew