isset go to url

Greetings,
i have a form where im checking what values were chose from a dropdown menu. At the moment if echo’ing back the values to the page, although id like to add a url in there. Suggestions please.

[php]<?
if (!isset($_POST[“menu”]) and ($_POST[“date”])){
echo “[please select appliance and date…]”;
}else{
echo $_POST[“menu”]."
";
echo $_POST[“date”];
// go to a url: http:// $_POST[“menu”].$_POST[“date”].html
}
?>[/php]

The “header” function allows you to “redirect” the user to other pages.

So your “go to a url” line would be something like this:

  header("Location: http://" .  $_POST["menu"] . $_POST["date"] . ".html");

It is quite often better to handle it this way:

 $url = "http://" . $_POST["menu"] . $_POST["date"] . ".html";
 header("Location: " . $url);

Because it is easier to debug it by echo’ing the $url variable to see what is inside it.

Hope that is what you needed…

hi Ernie,
how can i get the date value from the drop down as follows: I tried <?echo $TODAY"?> but it’s not working.
The $TODAY variable displays fine from the dropdown but its not capturing the value

[php]Date

" <? echo $TODAY ?> </select

<? if (isset($_POST["menu"]) and ($_POST["date"])){ echo $_POST["menu"]."
"; echo $_POST["date"]; header("Location: http://" . $_POST["menu"] . $_POST["date"] . ".html"); } ?>

[/php]

Well, first, since PHP code always is handled SERVER-SIDE and then posts it’s results to the browser,
I usually place my PHP code at the beginning of the page. It just seems normal to me to think of the
PHP code executing first, then the HTML/CSS/JS…

Also, you have a very odd line of a disabled OPTION value in your SELECT’s drop-down.
Can you explain why that is there? I mean, it should not really be there as it can never
be used as it is disabled. I do not understand that line.

Now, you echo a variable named “$TODAY”… BUT, I do not see in your code where you create that
variable or where you set the value of it. Or, did you just not show that code?

Also, usually there is a “DEFAULT” value that you use inside of a SELECT clause. This is the value that
you want the user to be stuck with if they do not adjust the drop-down setting. If you use that instead
of the odd line you have, then you do not need to check to see if the SELECT ISSET(). You just use the
value inside. Also, you should never create a drop-down with just one option. It does not make sense
to do that. If the results is always the same, just leave the drop-down out completely.

Lastly, your pull the value of the “menu” field from your form, but, there is no “menu” field on the page.

Very confused on your code and what you are trying to do here… Please explain what you want this
to do and we can help you put it in place…

i probably didn’t describe my issue clear enough. So the "
param just maked the default drop down choice empty when you load the page. $TODAY is defined further up in the code. There will be multiple options in the form. So when a user selects a choice. I just need the $TODAY variable to be interpolated inside the form as the value. So instead of:

[php]<? echo $TODAY ?>[/php]

i’d like

[php]<? echo $TODAY ?>[/php]

that’s why i was trying:

[php]<? echo $TODAY ?>[/php]

You forgot to put ‘;’ after $TODAY… I don’t know how many times I have forgotten a semicolon and debugged for hours.

Yes, Bishop, I just did not understand and was not clear there was other code on your page.

So, yes, you pull a drop-down just like any other POSTED field value. Using $somevar=$_POST[“somefield”]…
And, yes, then, to display that value, you simply ECHO it as in echo $somevar;
You can also as you showed, enter that same data inside an option value.

BUT, you can not pull an option value and place it inside itself. That would not make sense at all.

So, what you are doing should work. Most of the drop-downs that I work with are filled with text and
values from a database. Once the user selects an item, it is pulled and their choice is saved to the DB
or just used to display other items. Thanks for explaining the hidden option. I usually use a default
setting like “Select your date” or “Please select one of these”.

Well, since your code should be working, as you can place your variable $TODAY inside an OPTION
value, are you sure that the $TODAY variable is being created?

Russ! Thank you! I missed that one! I missed it… Very Nice Catch!

Thanks! I think the reason I caught it is because I made the exact same mistake today.

Sponsor our Newsletter | Privacy Policy | Terms of Service