ChronoEngine Forums
Welcome, Guest
Please Login or Register.    Lost Password?
Re:State/Province dropdown (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:State/Province dropdown
#5798
rodsdesign (User)
Junior Boarder
Posts: 32
graphgraph
User Offline Click here to see the profile of this user
State/Province dropdown 4 Months, 2 Weeks ago Karma: 0  
Hi all,

I'm sure you have used something like this - but in case you're always copying and pasting a drop down for states, I created an include that I have used a lot!

1. Copy and paste this code into a file (I call it stateselect.php) and put it somewhere within your joomla installation (I usually create a directory called myincludes)
Code for stateselect.php:
Code:

<select name='state' size='1'> <option value=''>Choose a State</option> <option value='AK' <?php if ($_POST['state'] == 'AK') echo 'selected='selected''; ?>>Alaska</option> <option value='AL' <?php if ($_POST['state'] == 'AL') echo 'selected='selected''; ?>>Alabama</option> <option value='AR' <?php if ($_POST['state'] == 'AR') echo 'selected='selected''; ?>>Arkansas</option> <option value='AZ' <?php if ($_POST['state'] == 'AZ') echo 'selected='selected''; ?>>Arizona</option> <option value='CA' <?php if ($_POST['state'] == 'CA') echo 'selected='selected''; ?>>California</option> <option value='CO' <?php if ($_POST['state'] == 'CO') echo 'selected='selected''; ?>>Colorado</option> <option value='CT' <?php if ($_POST['state'] == 'CT') echo 'selected='selected''; ?>>Connecticut</option> <option value='DC' <?php if ($_POST['state'] == 'DC') echo 'selected='selected''; ?>>District of Columbia</option> <option value='DE' <?php if ($_POST['state'] == 'DE') echo 'selected='selected''; ?>>Delaware</option> <option value='FL' <?php if ($_POST['state'] == 'FL') echo 'selected='selected''; ?>>Florida</option> <option value='GA' <?php if ($_POST['state'] == 'GA') echo 'selected='selected''; ?>>Georgia</option> <option value='HI' <?php if ($_POST['state'] == 'HI') echo 'selected='selected''; ?>>Hawaii</option> <option value='IA' <?php if ($_POST['state'] == 'IA') echo 'selected='selected''; ?>>Iowa</option> <option value='ID' <?php if ($_POST['state'] == 'ID') echo 'selected='selected''; ?>>Idaho</option> <option value='IL' <?php if ($_POST['state'] == 'IL') echo 'selected='selected''; ?>>Illinois</option> <option value='IN' <?php if ($_POST['state'] == 'IN') echo 'selected='selected''; ?>>Indiana</option> <option value='KS' <?php if ($_POST['state'] == 'KS') echo 'selected='selected''; ?>>Kansas</option> <option value='KY' <?php if ($_POST['state'] == 'KY') echo 'selected='selected''; ?>>Kentucky</option> <option value='LA' <?php if ($_POST['state'] == 'LA') echo 'selected='selected''; ?>>Louisiana</option> <option value='MA' <?php if ($_POST['state'] == 'MA') echo 'selected='selected''; ?>>Massachusetts</option> <option value='MD' <?php if ($_POST['state'] == 'MD') echo 'selected='selected''; ?>>Maryland</option> <option value='ME' <?php if ($_POST['state'] == 'ME') echo 'selected='selected''; ?>>Maine</option> <option value='MI' <?php if ($_POST['state'] == 'MI') echo 'selected='selected''; ?>>Michigan</option> <option value='MN' <?php if ($_POST['state'] == 'MN') echo 'selected='selected''; ?>>Minnesota</option> <option value='MO' <?php if ($_POST['state'] == 'MO') echo 'selected='selected''; ?>>Missouri</option> <option value='MS' <?php if ($_POST['state'] == 'MS') echo 'selected='selected''; ?>>Mississippi</option> <option value='MT' <?php if ($_POST['state'] == 'MT') echo 'selected='selected''; ?>>Montana</option> <option value='NC' <?php if ($_POST['state'] == 'NC') echo 'selected='selected''; ?>>North Carolina</option> <option value='ND' <?php if ($_POST['state'] == 'MD') echo 'selected='selected''; ?>>North Dakota</option> <option value='NE' <?php if ($_POST['state'] == 'ME') echo 'selected='selected''; ?>>Nebraska</option> <option value='NH' <?php if ($_POST['state'] == 'NH') echo 'selected='selected''; ?>>New Hampshire</option> <option value='NJ' <?php if ($_POST['state'] == 'NJ') echo 'selected='selected''; ?>>New Jersey</option> <option value='NM' <?php if ($_POST['state'] == 'NM') echo 'selected='selected''; ?>>New Mexico</option> <option value='NV' <?php if ($_POST['state'] == 'NV') echo 'selected='selected''; ?>>Nevada</option> <option value='NY' <?php if ($_POST['state'] == 'NY') echo 'selected='selected''; ?>>New York</option> <option value='OH' <?php if ($_POST['state'] == 'OH') echo 'selected='selected''; ?>>Ohio</option> <option value='OK' <?php if ($_POST['state'] == 'OK') echo 'selected='selected''; ?>>Oklahoma</option> <option value='OR' <?php if ($_POST['state'] == 'OR') echo 'selected='selected''; ?>>Oregon</option> <option value='PA' <?php if ($_POST['state'] == 'PA') echo 'selected='selected''; ?>>Pennsylvania</option> <option value='PR' <?php if ($_POST['state'] == 'PR') echo 'selected='selected''; ?>>Puerto Rico</option> <option value='RI' <?php if ($_POST['state'] == 'RI') echo 'selected='selected''; ?>>Rhode Island</option> <option value='SC' <?php if ($_POST['state'] == 'SC') echo 'selected='selected''; ?>>South Carolina</option> <option value='SD' <?php if ($_POST['state'] == 'SD') echo 'selected='selected''; ?>>South Dakota</option> <option value='TN' <?php if ($_POST['state'] == 'TN') echo 'selected='selected''; ?>>Tennessee</option> <option value='TX' <?php if ($_POST['state'] == 'TX') echo 'selected='selected''; ?>>Texas</option> <option value='UT' <?php if ($_POST['state'] == 'UT') echo 'selected='selected''; ?>>Utah</option> <option value='VA' <?php if ($_POST['state'] == 'VA') echo 'selected='selected''; ?>>Virginia</option> <option value='VT' <?php if ($_POST['state'] == 'VT') echo 'selected='selected''; ?>>Vermont</option> <option value='WA' <?php if ($_POST['state'] == 'WA') echo 'selected='selected''; ?>>Washington</option> <option value='WI' <?php if ($_POST['state'] == 'WI') echo 'selected='selected''; ?>>Wisconsin</option> <option value='WV' <?php if ($_POST['state'] == 'WV') echo 'selected='selected''; ?>>West Virginia</option> <option value='WY' <?php if ($_POST['state'] == 'WY') echo 'selected='selected''; ?>>Wyoming</option> <option value=''>Canadian Provinces</option> <option value='AB' <?php if ($_POST['state'] == 'AB') echo 'selected='selected''; ?>>Alberta</option> <option value='BC' <?php if ($_POST['state'] == 'BC') echo 'selected='selected''; ?>>British Columbia</option> <option value='MB' <?php if ($_POST['state'] == 'MB') echo 'selected='selected''; ?>>Manitoba</option> <option value='NB' <?php if ($_POST['state'] == 'NB') echo 'selected='selected''; ?>>New Brunswick</option> <option value='NF' <?php if ($_POST['state'] == 'NF') echo 'selected='selected''; ?>>Newfoundland</option> <option value='NT' <?php if ($_POST['state'] == 'NT') echo 'selected='selected''; ?>>Northwest Territories</option> <option value='NS' <?php if ($_POST['state'] == 'NS') echo 'selected='selected''; ?>>Nova Scotia</option> <option value='NU' <?php if ($_POST['state'] == 'NU') echo 'selected='selected''; ?>>Nunavut</option> <option value='ON' <?php if ($_POST['state'] == 'ON') echo 'selected='selected''; ?>>Ontario</option> <option value='PE' <?php if ($_POST['state'] == 'PE') echo 'selected='selected''; ?>>Prince Edward Island</option> <option value='QC' <?php if ($_POST['state'] == 'QC') echo 'selected='selected''; ?>>Quebec</option> <option value='SK' <?php if ($_POST['state'] == 'SK') echo 'selected='selected''; ?>>Saskatchewan</option> <option value='YT' <?php if ($_POST['state'] == 'YT') echo 'selected='selected''; ?>>Yukon Territory</option> </select>
2. in your form, where you'd normally put the <select> </select>, put
Code:

<?php include ( 'myincludes/stateselect.php' );?>
that's it - the states will be included in the form, and they'll be remembered if someone puts in the wrong text for image verification. hope that helps someone
 
Report to moderator   Logged Logged  
 
Last Edit: 2008/05/15 01:56 By GreyHead. Reason: fixed html entities
  The administrator has disabled public write access.
#5834
GreyHead (Admin)
Admin
Posts: 2809
graph
User Offline Click here to see the profile of this user
Re:State/Province dropdown 4 Months, 2 Weeks ago Karma: 59  
Hi Rod,

This is neat - I like the idea of using and include file for this. It prompted me to go back and look to see if Joomla had a buil-in states list (it doesn't as far as i can see). However I did find some built in constructor code that lets you do this with less repetition
Code:

<?php $USStateArray = Array( 'AK' => 'Alaska', 'AL' => 'Alabama', 'AR' => 'Arkansas', 'AZ' => 'Arizona', 'CA' => 'California', 'CO' => 'Colorado', 'CT' => 'Connecticut', 'DC' => 'District of Columbia', 'DE' => 'Delaware', 'FL' => 'Florida', 'GA' => 'Georgia', 'HI' => 'Hawaii', 'IA' => 'Iowa', 'ID' => 'Idaho', 'IL' => 'Illinois', 'IN' => 'Indiana', 'KS' => 'Kansas', 'KY' => 'Kentucky', 'LA' => 'Louisiana', 'MA' => 'Massachusetts', 'MD' => 'Maryland', 'ME' => 'Maine', 'MI' => 'Michigan', 'MN' => 'Minnesota', 'MO' => 'Missouri', 'MS' => 'Mississippi', 'MT' => 'Montana', 'NC' => 'North Carolina', 'MD' => 'North Dakota', 'ME' => 'Nebraska', 'NH' => 'New Hampshire', 'NJ' => 'New Jersey', 'NM' => 'New Mexico', 'NV' => 'Nevada', 'NY' => 'New York', 'OH' => 'Ohio', 'OK' => 'Oklahoma', 'OR' => 'Oregon', 'PA' => 'Pennsylvania', 'PR' => 'Puerto Rico', 'RI' => 'Rhode Island', 'SC' => 'South Carolina', 'SD' => 'South Dakota', 'TN' => 'Tennessee', 'TX' => 'Texas', 'UT' => 'Utah', 'VA' => 'Virginia', 'VT' => 'Vermont', 'WA' => 'Washington', 'WI' => 'Wisconsin', 'WV' => 'West Virginia', 'WY' => 'Wyoming' ); foreach ( $USStateArray as $abb => $name ) { $options[] = mosHTML::makeOption($abb, $name); } $select = mosHTML::selectList($options, 'state[]', 'size='1'', 'value', 'text', $_POST['state']); echo $select; ?> <br /> <input name='state[]' type='hidden' />
This works in a ChronoForms form. A couple of things to notice though: (a) I used the mosHTML library (documented in the Joomla Developers Manual) really just to see if it works, you could do the same with a foreach loop to generate <option> tags. (b) to get the result into ChronoForms I had to add that dummy hidden input - it's only there so that when ChronoForms parses the HTML it finds the field name. Bob
 
Report to moderator   Logged Logged  
 
Last Edit: 2008/05/15 01:57 By GreyHead.
 
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
  The administrator has disabled public write access.
#8129
sailsmart (User)
Junior Boarder
Posts: 21
graphgraph
User Offline Click here to see the profile of this user
drop down menu simplified 1 Month, 3 Weeks ago Karma: 0  
You mean I have to put in all this code and it's going to post the drop down answer? Do I have to build arrays?
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#8146
admin (Admin)
Admin
Posts: 1570
graphgraph
User Online Now Click here to see the profile of this user
Re:drop down menu simplified 1 Month, 3 Weeks ago Karma: 22  
Both the codes posted will work fine, just pick anyone of them, Bob used the Joomla built in functions to make the dropdown through arrays, it makes it easier to show the selected entry too!

Cheers

Max
 
Report to moderator   Logged Logged  
 
ChronoForms Developer Thanks for using ChronoForms.
If you have any problems with ChronoForms please tell us.
If you like ChronoForms please post a review at Joomla.org
  The administrator has disabled public write access.
#8408
kai920 (User)
Senior Boarder
Posts: 40
graphgraph
User Offline Click here to see the profile of this user
Re:State/Province dropdown 1 Month, 3 Weeks ago Karma: 0  
Hi guys,

I am trying to utilize similar code in a form I am building. I would like to eventually move the array code into a PHP file so that it can be edited easily as the array of list values could change often.

Here is a simple example I tried to adapt - is there something wrong with this code?

Code:

<?php $Category = Array( 'Audio' => 'Audio', 'Blog' => 'Blog' ); foreach ( $Category as $cat => $category ) { $options[] = mosHTML::makeOption($cat, $category); } $select = mosHTML::selectList($options, 'category[]', 'size='1'', 'value', 'text', $_POST['category']); echo $select; ?> <br /> <input name='category[]' type='hidden' />
 
Report to moderator   Logged Logged  
  The administrator has disabled public write access.
#8412
GreyHead (Admin)
Admin
Posts: 2809
graph
User Offline Click here to see the profile of this user
Re:State/Province dropdown 1 Month, 3 Weeks ago Karma: 59  
Hi kai920,

It looks OK to my eyeball.

What happens when you use it?

Bob
 
Report to moderator   Logged Logged  
 
Bob Janes
info at greyhead.net
ChronoForms Support If you like ChronoForms please vote or post a review at Joomla.org
  The administrator has disabled public write access.
Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop


equalheight If you have any questions you can post to our forums and we will be glad to help ASAP

Members Login






Lost Password?
No account yet? Register

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for
goods and services provided by ChronoEngine.com

ChronoForms License

equalheightTo be able to continue working at this component we decided to get a small profit out of it but at the same time don't force everybody to pay in order to use this great component.

 

 From version 1.5 and up a link at the bottom of everyform created will be placed, saying "joomla professional work", the link will be to us here htttp://www.chronoengine.com, its illegal to remove this link from the source code unless you have a license,

so the license is very simply for the same ChronoForms component without a link, thats all!

This License is for 5 different websites ONLY. 

 

 However, in order to allow everybody to still use the component and even get out of this, the link is inside a div with class : chronoform , use this to hide the link by using different colors or whatever if you really can't pay, but of course the link is still exists at your page source.

 

The license is ONLY 25$ can be bought here :

 

Thank you!

 

ChronoEngine.com Team 

Joomla Templates and Joomla Tutorials