Page 1 of 1

Create New Form Value

Posted: Thu Jan 22, 2009 8:15 pm
by Becca800
Hey there, php is not my strong point. I can't write my own php to save my life, but if I have a snippet I can usually figure out how to tweak it.

I have a form which autopopulates a few form fields when the user enters his/her zip code, the city and state fields are populated from a mysql db. The state field is an abbreviated version of the state. I need to create a new value from the state value using php. So if the state is AL, I need to be able to have a new value "Alabama", if the state is CA, I need a new value for "california", etc. Does anyone know how I can do this? I need both values, so it isn't that I would need to rename the value. Thanks.

Re: Create New Form Value

Posted: Fri Jan 23, 2009 4:34 am
by ramya123
You can use Associative array in order to achieve this

Code: Select all

 
$state = array("AL"=>"Alabama","CA"=>"california");
 
Here we can use the values as keys and assign values to them.The ID keys can be used in a script:

Code: Select all

 
$state['AL'] = "Alabama";
$state['CA'] = "california";