iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-24-2005, 05:48 PM
richkoi's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Atlanta, GA
Posts: 451
richkoi RepRank 0
Default PHP - Using drop down form to pass multiple variables

I am trying to pass multiple variables for each selection on a form. So far this is my idea:

Code:
                      <select name="advanced" class="form" id="advanced">
                        <option value="?h=1" selected>Hedges</option>
                        <option value="?htmin=8&htmax=14&h=1">--Between 8 and 15 feet</option>
                        <option value="?htmin=15&htmax=20&h=1">--Between 15 and 20 feet</option>
                        <option value="?htmin=21&htmax=30&h=1">--Between 20 and 30 feet</option>
                        <option value="?htmin=31&htmax=50&h=1">--Between 30 and 50 feet</option>
                        <option value="?htmin=51&htmax=100&h=1">--50+ Feet</option>
                        <option value="?coldhardy=1">Cold Hardy</option>
                        <option value="?cr=c&coldhardy=1">--Clumpers</option>
                      </select>
I would like it to patch the "advanced" variable to the php file on submit. For example if you were to select "--Between 20 and 30 feet" on submit the url would show as url.php?htmin=21&htmax=30&h=1.

Am I going about this right?

Rich
__________________
Me
Reply With Quote
  #2 (permalink)  
Old 10-25-2005, 02:04 AM
Evic's Avatar
WebProWorld Pro
 
Join Date: Jul 2005
Location: Eielson AFB, AK
Posts: 174
Evic RepRank 0
Default

To do that would require some tricky javascript.

Why not just refer to the variable on the next page via the $_POST array?

Your recepient file:
Code:
<?php
if ($_POST['advanced'] == "hedges") {
  $min = 0;
  $max = 0;
  $selection = "hedges";
} elseif ($_POST['advanced'] == "8to15") {
  $min = 8;
  $max = 15;
  $selection = "bushes";
}
?>
etc.

Of course, you would need to change the values on your form, but that's no big deal. Also, check out PHP's switch structure - it will clean up the if... then, I only used it for ease-of-understanding.
__________________
Michael Wales

My Blog: GibThis: Video Game Blog
Reply With Quote
  #3 (permalink)  
Old 10-25-2005, 01:25 PM
richkoi's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Atlanta, GA
Posts: 451
richkoi RepRank 0
Default

Thanks. What I ended up doing is the following:

Code:
					 <form name="form2" method="post" onSubmit="return dropdown(this.advanced)">

<select name="advanced" class="form" id="advanced">
                        <option value="photos.php?h=1&s=1" <? if (($p==NULL)or($s==1)){ echo "selected"; }?>>Hedges</option>
                        <option value="photos.php?htmin=8&htmax=14&h=1&p=1&s=2" <? if ($s==2){ echo "selected"; } ?>>Between 8 and 15 feet</option>
                        <option value="photos.php?htmin=15&htmax=20&h=1&p=1&s=3" <? if ($s==3){ echo "selected"; } ?>>Between 15 and 20 feet</option>
                        <option value="photos.php?htmin=21&htmax=30&h=1&p=1&s=4" <? if ($s==4){ echo "selected"; } ?>>Between 20 and 30 feet</option>
                        <option value="photos.php?htmin=31&htmax=50&h=1&p=1&s=5" <? if ($s==5){ echo "selected"; } ?>>Between 30 and 50 feet</option>
                        <option value="photos.php?htmin=51&htmax=100&h=1&p=1&s=6" <? if ($s==6){ echo "selected"; } ?>>50+ Feet</option>
                        <option value="photos.php?coldhardy=1&p=1&s=7" <? if ($s==7){ echo "selected"; } ?>>Cold Hardy</option>
                        <option value="photos.php?cr=c&coldhardy=1&p=1&s=8" <? if ($s==8){ echo "selected"; } ?>>Clumpers</option>
                        <option value="photos.php?cr=r&coldhardy=1&p=1&s=9" <? if ($s==9){ echo "selected"; } ?>>Runners</option>
                        <option value="photos.php?h=1&coldhardy=1&p=1&s=10" <? if ($s==10){ echo "selected"; } ?>>Hedges</option>
                        <option value="photos.php?la=1&p=1&s=11" <? if ($s==11){ echo "selected"; } ?>>Landscape Accent</option>
						<option value="photos.php?culm=1&p=1&s=12" <? if ($s==12){ echo "selected"; } ?>>Unusual Culms</option>
                      </select>
It uses javascript to patch the $advanced variable into the url.

Rich
__________________
Me
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 06:01 AM.



Search Engine Optimization by vBSEO 3.3.0