/    Sign up×
Community /Pin to ProfileBookmark

submit form and it goes to php page

Hello all,

I have a basic form with 2 drop down boxes. One drop down box allows you to choose the year (e.g. 2007, 2008, 2009) and the other drop down box allows you to choose the month (e.g. 01, 02, 03, etc). The form, when the submit button is pressed, will go to a php url. I would like to make it so that the url is determined by the chosen month and year in the drop down boxes. For instance, if I choose 2008 for year and 09 for month, I woul dlike it to go to the following url when you press the submit button:

[url]http://www.something.com/index.php?year=2008&month=09[/url]

The year and month parameters in the url above would be determined by what is chosen in the 2 drop down boxes.

Any help would be greatly appreciated.

Thanks,
cedric

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@cedric813authorJan 01.2009 — This is the code I have for the form:

<i>
</i>&lt;form method="POST" action="index.php"&gt;
&lt;p align="center"&gt;&lt;b&gt;&lt;font size="2" face="Verdana"&gt;Year: &lt;/font&gt;&lt;/b&gt;&lt;font face="Verdana"&gt;&lt;b&gt;
&lt;select size="1" name="yeardrop"&gt;
&lt;?

$todaysyear=date("Y");


for($i=2007;$i&lt;=$todaysyear;$i++) {

if($i==$year) {
echo "&lt;option selected&gt;$i&lt;/option&gt;";
}
else {
echo "&lt;option&gt;$i&lt;/option&gt;";
}

}


?&gt;
&lt;/select&gt;
&lt;b&gt;&lt;font size="2" face="Verdana"&gt; &amp;nbsp;&amp;nbsp;Month: &lt;/font&gt;&lt;/b&gt;
&lt;select size="1" name="monthdrop"&gt;
&lt;?

$todaysyear=date("Y");


for($i=1;$i&lt;=12;$i++) {


if($i&lt;=9) {
$k='0'.$i;
}
else {
$k=$i;
}



if($k==$month) {
echo "&lt;option selected&gt;$k&lt;/option&gt;";
}
else {
echo "&lt;option&gt;$k&lt;/option&gt;";
}

}
?&gt;
&lt;/select&gt;
&lt;/b&gt;&lt;/font&gt;&lt;b&gt;&lt;font size="2" face="Verdana"&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/b&gt;&lt;font face="Verdana"&gt;&lt;b&gt;
&lt;input type="submit" value="Go" name="B1"&gt;
&lt;/b&gt;&lt;/font&gt;&lt;/p&gt;
&lt;/form&gt;


All the php stuff in the form is just to tell the page which years and months to put in each drop down box...as far as i know.
Copy linkTweet thisAlerts:
@KryptonianJan 01.2009 — Hi Cedric813. If you change your form's method attribute to "get", the action address will automatically change to this when you submit your form: "index.php?yeardrop=[selected year]&monthdrop=[selected month]". If you really want to change that to "year" and "month", just change the name attributes of your select elements. Wonderfully simple, eh? ?
×

Success!

Help @cedric813 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...