passing element value as url

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sobha
Forum Commoner
Posts: 56
Joined: Wed Jul 15, 2009 9:08 pm

passing element value as url

Post by sobha »

Hi,
What is the correct syntax to be used in line with red color?
<form method="post" action="sample.php?month=month.value">
<select name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
</select>
Regards,
Sobha
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: passing element value as url

Post by requinix »

Don't include it.

By defining <select name="month"> you are already including the value in the form submission. Access it in your PHP script with $_POST["month"].
sobha
Forum Commoner
Posts: 56
Joined: Wed Jul 15, 2009 9:08 pm

Re: passing element value as url

Post by sobha »

$_POST["month"] is retreiving value outside the if condition.But not retreiving value inside if condition.
if ($_POST['submit']) {
//....
}
<form>
<input type="submit">
</form>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: passing element value as url

Post by requinix »

I can't even tell what you're saying, but if it's not working then you're doing it wrong.

Code: Select all

<html>
<body>
<?php
 
if (isset($_POST["month"])) echo "<p>Month #", $_POST["month"], "</p>\n";
 
?>
<form method="post">
<p><select name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
</select> <input type="submit">
</form>
</body>
</html>
webmonkey88
Forum Newbie
Posts: 20
Joined: Fri Aug 14, 2009 4:30 am

Re: passing element value as url

Post by webmonkey88 »

lol go to w3schools
Post Reply