States and Countries Dropdowns

Does anyone know if there is an easier way to create State and Country dropdowns without having to manually enter in each state and country to generate the form?

Any help would be appreciated.

Stig Stig, 7 years ago

Hi zufferguffin,
if you create the State and Country custom fields as text fields, you can replace them manually in the HTML with dropdowns. That way you won't have to enter all the options in CM.

Stig


The Campaign Monitor Blog – HTML email smarts to go with your good looks.
zufferguffin, 7 years ago

Thanks stig. Sounds like a plan.

danwoodward, 7 years ago

I was banging my head against a wall to figure this out without writing something fancy using the api code. And I figured it out using a little jquery.

Ok so the setup is:
Make custom field, that is just a text field. Get the form code and give the "Country" input a unique id. And stick a country select menu in there without any attributes.

so your code should look something like this

    <form action="http://XXXXXXXX.createsend.com/t/y/s/XXXXXj/" method="post">
        <p>
            <label for="name">Name:</label><br />
            <input type="text" name="cm-name" id="name" />
        </p>
        
        <p>
            <label for="xxxxx-xxxxx">Email:</label><br />
            <input type="text" name="cm-xxxxx-xxxxx" id=xxxxx-xxxxx" class="text" />
        </p>


<select id="country_list">
<option value="">Country...</option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
<option value="">200 more countries.....</option>
</select>


        <p>
            <label for="Country"><Country:</label><br />
            <span class=""><input type="text" class="text" name="cm-xxxxxx" id="Country" value="Your Country" /></span>
        </p>
        
        <input type="submit" value="subscribe" />
    </form>

Then roll up a little jquery.

    
  $("select").change(function () {
          var str = "";
          $("select option:selected").each(function () {
                str = $(this).text();
              });
          $("input#Country").empty()
          $("input#Country").val(str);
  });

And thats it, the select menu populates the text field and that value gets submitted.  You can then go a step further and hide the text field all together and just show the select menu and the user won't have any idea. Just be careful, this solution will only work if the user has javascript turned on, which is most of the time....

woodsikov woodsikov, 7 years ago
danwoodward :

I was banging my head against a wall to figure this out without writing something fancy using the api code. And I figured it out using a little jquery.

Maybe I'm missing the point but this seems ... pointless - just use the select control because at the server end everything is just name/value pairs and the processing script doesn't know the difference between a select and a textbox.

Which I think is what Stig was suggesting.


--
Dean
PDD2010, 6 years ago

Hi - could anyone please elaborate a little more on what Stig was referring to? danwoodward's solution seems a little OTT!

I've created the code from CM and set up the form on the client site.

But how best to add the drop down for city, state and country - thereby avoiding spelling errors etc
And how to populate that / where to pull data from?

Thanks

davidaf davidaf, 6 years ago

PDD2010, Stig was just saying that you can keep the state and country custom fields as text fields in your subscriber list (rather than multiple option fields), but in the subscribe form on your site you can convert those fields to drop down selects for your users (to keep the data clean).


The Campaign Monitor Blog – HTML email smarts to go with your good looks
PDD2010, 6 years ago

Hi Davida

I understand that thanks.  I was wondering if there might be some example code already written with that included!

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098