jquerysmartystreets

Smartystreets not auto populating zip code


I set up SmartyStreets on a form I am using and it works great, except the ZIP Code is not automatically verifying after the address is entered. The address dropdown works okay and the addresses show up but the ZIP is always blank because it thinks I did not enter enough information. The error message does not include the city/state.

I have this on a few other forms, and they all auto-verify the address. What could I be missing here? My form is mapped correctly. I checked out some other Stack Overflow questions related to the same thing and their fix did not work for me unfortunately.

I attempt to select an address from the drop down and SmartyStreets comes back with: "You Didn't Enter Enough Information". It seems to be stripping out the city and state.

//SmartyStreets Address Autocomplete and Verification
        $.LiveAddress({
            key: 'Not gonna include this ;)',
            debug: false,
            waitForStreet: false,
            autocomplete: 5,
            enforceVerification: false,
            verifySecondary: true,
            target: "US",
            waitForStreet: true,
            invalidMessage: "Address not found. Please enter zip code.",
            addresses: [{
                id: 'enterpropertyaddress',
                address1: '#PropertyStreetAddress',
                postal_code: '#PropertyZip',
                locality: '#PropertyCity',
                administrative_area: '#PropertyState'
            }]
        });

// HTML elements
<input
    class="form-control"
    id="PropertyStreetAddress"
    name="PropertyStreetAddress"
    placeholder="Property Address"
    required="required"
    type="text"
    value=""
    autocomplete="smartystreets" >

<input
    class="form-control"
    data-val="true"
    data-val-regex="Please enter a valid zip code."
    data-val-regex-pattern="^\d{5}(-\d{4})?$"
    data-val-required="Zip Code is required"
    id="PropertyZip"
    name="PropertyZip"
    placeholder="Zip Code"
    required="required"
    type="text"
    value=""
    autocomplete="smartystreets" >

Solution

  • Figured out my answer! It was a mapping thing for me. Somehow the city/state accidentally got commented out. That explains why smartystreets could not figure out the city/state of my address and couldn't validate it.

    They are hidden fields so nobody noticed at the time. Every part of this in smarty streets needs to be on the form you are working with, otherwise it will fail.

    addresses: [{
                    id: 'enterpropertyaddress',
                    address1: '#PropertyStreetAddress',
                    postal_code: '#PropertyZip',
                    locality: '#PropertyCity',
                    administrative_area: '#PropertyState'
                }]